xslt 2.0 - Splitfunction gives troubles -
i'm facing following problem or challenge. i've element in source xml can have 450 characters. xslt want transform chunks of 75 characters.
... <t61> <parentinfo>someinfo</parentinfo> <t86> <info>abcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890</info> </t86> </t61> ... the output generate should like:
<t31> <x>abcdefghijklmnopqrstuvwxyz01234567890</x> </t31> <t31> <x>abcdefghijklmnopqrstuvwxyz01234567890</x> </t31> in code use template t61 work. thought create template t86 , call inside t61 template seems not work because i've complete string. created function split string in parts of 75. outcome of function still complete string.
i used function earlier post:
<xsl:function name="my:splititup" as="xs:string"> <xsl:param name="input" as="xs:string"/> <xsl:param name="chunk-size" as="xs:integer"/> <xsl:value-of> <xsl:for-each-group select="string-to-codepoints($input)" group-by="(position() -1) idiv $chunk-size"> <xsl:sequence select="codepoints-to-string(current-group())"/> </xsl:for-each-group> </xsl:value-of> </xsl:function> ... <xsl:template match="t86"> <xsl:for-each select="my:splititup(info, 75)"> <t31> <communication> <xsl:value-of select="." /> </communication> </t31> </xsl:for-each> </xsl:template> this structure result in complete string. in debug see split concatenates result together. can somehow come out of function?
best regards dirk
please have xslt need set <xsl:param name="stringrequired" select="xs:integer(13)"/> chunk text:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xs="http://www.w3.org/2001/xmlschema"> <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" encoding="utf-8"/> <xsl:param name="xml"> <info>abcdefghijklmnopqrstuvwxyz01234567890abcdefghijklmnopqrstuvwxyz01234567890</info> </xsl:param> <xsl:param name="stringrequired" select="xs:integer(13)"/> <xsl:param name="xmllenfgh" select="string-length($xml)"/> <xsl:template match="/"> <xsl:choose> <xsl:when test="$xmllenfgh gt $stringrequired"> <xsl:call-template name="getpart"/> </xsl:when> <xsl:otherwise> <t31> <x> <xsl:value-of select="$xml/info"/> </x> </t31> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="getpart"> <xsl:param name="xml" select="$xml"/> <xsl:param name="stringrequired" select="$stringrequired"/> <xsl:param name="xmllenfgh" select="$xmllenfgh"/> <xsl:message> <xsl:value-of select="$xml"/> </xsl:message> <xsl:if test="$xmllenfgh gt $stringrequired"> <t> <x> <xsl:value-of select="substring($xml,1,$stringrequired)"/> </x> </t> <xsl:call-template name="getpart"> <xsl:with-param name="xml" select="substring($xml,string-length(substring($xml,1,$stringrequired)))"/> <xsl:with-param name="xmllenfgh" select="string-length(substring($xml,string-length(substring($xml,1,$stringrequired))))"/> <xsl:with-param name="stringrequired" select="$stringrequired"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> output:
<t xmlns:xs="http://www.w3.org/2001/xmlschema"> <x>abcdefghijklm</x> </t> <t xmlns:xs="http://www.w3.org/2001/xmlschema"> <x>mnopqrstuvwxy</x> </t> <t xmlns:xs="http://www.w3.org/2001/xmlschema"> <x>yz01234567890</x> </t> <t xmlns:xs="http://www.w3.org/2001/xmlschema"> <x>0abcdefghijkl</x> </t> <t xmlns:xs="http://www.w3.org/2001/xmlschema"> <x>lmnopqrstuvwx</x> </t> <t xmlns:xs="http://www.w3.org/2001/xmlschema"> <x>xyz0123456789</x> </t>
Comments
Post a Comment