|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Doubled output of text nodes
I have an application which produces XML docs similar to this one:
---------------------------------------------------------
<?xml version="1.0"?>
<root>
<node>
<node>Topic A
<node>Subtopic A.1
<node>Subtopic A.1.a</node>
</node>
</node>
<node>Topic B</node>
</node>
</root>
---------------------------------------------------------
I wish to use XLT to add unique id's to each node element, but otherwise
copy the content unchanged to the output. I have worked out this XSLT:
---------------------------------------------------------
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="node">
<xsl:variable name="id">
<xsl:value-of select="generate-id()" />
</xsl:variable>
<node id="{$id}"><xsl:value-of select="text()[position()=1]" />
<xsl:apply-templates />
</node>
</xsl:template>
<xsl:template match="root">
<xsl:variable name="id">
<xsl:value-of select="generate-id()" />
</xsl:variable>
<root id="{$id}">
<xsl:apply-templates />
</root>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------------------
The output produces two copies of the desired text nodes:
---------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<root id="N400001">
<node id="N400004">
<node id="N400006">Topic A
Topic A
<node id="N400008">Subtopic A.1
Subtopic A.1
<node id="N40000A">Subtopic A.1.aSubtopic A.1.a</node>
</node>
</node>
<node id="N40000F">Topic BTopic B</node>
</node>
</root>
---------------------------------------------------------
I imagine that my problem is in the XPath expression, but I haven't been
able to see how I might express it differently.
Any suggestions?
Thanks.
--
Charles Knell
cknell@xxxxxxxxxx - email
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








