Subject: Re: [xsl] Doubled output of text nodes From: "Charles Knell" <cknell@xxxxxxxxxx> Date: Thu, 11 Jul 2002 09:58:34 -0700 |
Sorry to trouble you. I found what I needed in chapter 4 of XSLT Programmer's Reference, 2nd Edition. -- Charles Knell cknell@xxxxxxxxxx - email ---- "Charles Knell" <cknell@xxxxxxxxxx> wrote: > 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 > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Doubled output of text no, Marrow | Thread | RE: [xsl] Doubled output of text no, Matthew L. Avizinis |
Re: [xsl] Doubled output of text no, Marrow | Date | Re: [xsl] Doubled output of text no, Thomas B. Passin |
Month |