[Home] [By Thread] [By Date] [Recent Entries]
Abel rightly said, your desired output is not well-formed XML (so it cannot be consumed by any XML 1.x complaint tool / parser). Assuming that is an oversight on your part, here is the solution which Abel outlined: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:param name="string" /> <xsl:template match="/">
<AllCodes>
<xsl:call-template name="tokenize">
<xsl:with-param name="string" select="$string" />
<xsl:with-param name="delim" select="','" />
</xsl:call-template>
</AllCodes>
</xsl:template><xsl:template name="tokenize"> <xsl:param name="string" /> <xsl:param name="delim" /> <xsl:choose>
<xsl:when test="contains($string, $delim)">
<Code value="{substring($string, 1, 1)}">
<Description><xsl:value-of select="substring-before($string,
$delim)" /></Description>
</Code>
<xsl:call-template name="tokenize">
<xsl:with-param name="string"
select="substring-after($string, $delim)" />
<xsl:with-param name="delim" select="$delim" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<Code value="{substring($string, 1, 1)}">
<Description><xsl:value-of select="$string" /></Description>
</Code>
</xsl:otherwise>
</xsl:choose>
</xsl:template></xsl:stylesheet> When the above stylesheet is applied to XML: <?xml version="1.0" encoding="UTF-8"?> <x/> (this is any dummy XML) The output produced is: <?xml version="1.0" encoding="UTF-8"?> <AllCodes> <Code value="A"> <Description>ABC</Description> </Code> <Code value="D"> <Description>DEF</Description> </Code> <Code value="G"> <Description>GHI</Description> </Code> </AllCodes> I used Xalan-J 2.7.0 as following, to invoke the transformation: java org.apache.xalan.xslt.Process -in test.xml -xsl test.xsl -PARAM string ABC,DEF,GHI Hope this helps. On 3/21/07, Lalit.Chanchlani@xxxxxxxxxxxxxxxxxx <Lalit.Chanchlani@xxxxxxxxxxxxxxxxxx> wrote: Hi, -- Regards, Mukul Gandhi
|

Cart



