[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Doubled output of text nodes

Subject: Re: Doubled output of text nodes
From: "Charles Knell" <cknell@xxxxxxxxxx>
Date: Thu, 11 Jul 2002 09:58:34 -0700
charles knell
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.