This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Doubled output of text nodes


Sorry to trouble you. I found what I needed in chapter 4 of XSLT Programmer's
Reference, 2nd Edition.

-- 
Charles Knell
cknell@onebox.com - email


---- "Charles Knell" <cknell@onebox.com> 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@onebox.com - 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]