Simple XSLT template -
there xml document:
<data>how;many;i;can;tell;you</data>
need xml using xslt version 1:
<manydata> <onedata>how</onedata> <onedata>many</onedata> <onedata>i</onedata> <onedata>can</onedata> <onedata>tell</onedata> <onedata>you</onedata> </manydata>
how can it?
update: output format must xml.
this recursive solution 1 of shortest possible:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="data"> <manydata><xsl:apply-templates/></manydata> </xsl:template> <xsl:template match="text()" name="tokenize"> <xsl:param name="ptext" select="."/> <xsl:if test="string-length($ptext)"> <onedata> <xsl:value-of select= "substring-before(concat($ptext,';'),';')"/> </onedata> <xsl:call-template name="tokenize"> <xsl:with-param name="ptext" select= "substring-after($ptext,';')"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet>
when transformation applied on provided xml document;
<data>how;many;i;can;tell;you</data>
the wanted, correct result produced:
<manydata> <onedata>how</onedata> <onedata>many</onedata> <onedata>i</onedata> <onedata>can</onedata> <onedata>tell</onedata> <onedata>you</onedata> </manydata>
Comments
Post a Comment