[Home] [By Thread] [By Date] [Recent Entries]
At 2009-11-08 18:58 -0800, road speeder wrote:
Hi, I have the following xml data: Without using any proprietary extensions, I suggest you write out the <Details> element to a text file, transform it as an XML file, and then in a second pass on the first file pull in the transformed result again as a text file. Using standard XSLT you cannot parse character data using template rules. I hope this helps. The example stylesheets below produce the output you cite above without using any extensions, though I have no idea if it would meet any other requirements you aren't stating as I'm only using the one file for testing. . . . . . . . . . . . . Ken T:\ftemp>type speeder.xml <Sale><Site>101</Site> <Details><![CDATA[<?xml version="1.0"?><items><item>desk</item><cost>10</cost></items> ]]> </Details> </Sale> T:\ftemp>call xslt2 speeder.xml speeder1.xsl temp.xml T:\ftemp>type temp.xml <?xml version="1.0"?><items><item>desk</item><cost>10</cost></items> T:\ftemp>call xslt2 temp.xml speeder2.xsl temp2.xml T:\ftemp>type temp2.xml <?xml version="1.0" encoding="UTF-8"?><skus><sku>desk</sku><amount>10</amount></skus> T:\ftemp>call xslt2 speeder.xml speeder3.xsl speeder.out.xml "detailsfile=temp2.xml" T:\ftemp>type speeder.out.xml <?xml version="1.0" encoding="UTF-8"?><SalesItem><Location>101</Location> <SkuDetails><![CDATA[<?xml version="1.0" encoding="UTF-8"?><skus><sku>desk</sku><amount>10</amount></skus>]]></SkuDetails> </SalesItem> T:\ftemp>type speeder1.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:value-of select="Sale/Details"/> </xsl:template> </xsl:stylesheet>
T:\ftemp>type speeder2.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"><xsl:template match="items">
<skus>
<xsl:apply-templates/>
</skus>
</xsl:template><xsl:template match="item">
<sku>
<xsl:apply-templates/>
</sku>
</xsl:template><xsl:template match="cost">
<amount>
<xsl:apply-templates/>
</amount>
</xsl:template></xsl:stylesheet> T:\ftemp>type speeder3.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"><xsl:param name="detailsfile"/> <xsl:output cdata-section-elements="SkuDetails"/> <xsl:template match="Sale">
<SalesItem>
<xsl:apply-templates/>
</SalesItem>
</xsl:template><xsl:template match="Site">
<Location>
<xsl:apply-templates/>
</Location>
</xsl:template><xsl:template match="Details">
<SkuDetails>
<xsl:value-of select="unparsed-text($detailsfile)"/>
</SkuDetails>
</xsl:template></xsl:stylesheet> T:\ftemp>rem Done!
|

Cart



