Subject: Re: [xsl] Identifier attribute (was: Re: [xsl] Creating Hierarchy) From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Thu, 23 Oct 2008 11:06:12 -0400 |
Thanks for your help with this. Using the technique you've suggested I've been able to successfully add the id values with two separate XSL transform documents, but I can't get it to work as a two-pass process in a single stylesheet.
...
How do I combine these two transforms into a single stylesheet using the two-pass approach? I can't get this to work...
T:\ftemp>type rowan.xml <?xml version="1.0"?> <mytree> <node> <name>Root of my tree</name> <level>0</level> </node> <node> <name>Child of root</name> <level>1</level> </node> <node> <name>Another child of root</name> <level>1</level> </node> <node> <name>Grandchild of root</name> <level>2</level> </node> <node> <name>Yet another child of root</name> <level>1</level> </node> </mytree>
T:\ftemp>type rowan1.xml <?xml version="1.0" encoding="UTF-8"?> <newnode id=""> <name>Root of my tree</name> <newnode id=""> <name>Child of root</name> </newnode> <newnode id=""> <name>Another child of root</name> <newnode id=""> <name>Grandchild of root</name> </newnode> </newnode> <newnode id=""> <name>Yet another child of root</name> </newnode> </newnode> T:\ftemp>type rowan2.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsl:output method="xml" indent="yes"/> <xsl:template match="*[@id]"> <xsl:copy> <xsl:attribute name="id"> <xsl:number level="any" count="*[@id]"/> </xsl:attribute> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
T:\ftemp>type rowan2.xml <?xml version="1.0" encoding="UTF-8"?> <newnode id="1"> <name>Root of my tree</name> <newnode id="2"> <name>Child of root</name> </newnode> <newnode id="3"> <name>Another child of root</name> <newnode id="4"> <name>Grandchild of root</name> </newnode> </newnode> <newnode id="5"> <name>Yet another child of root</name> </newnode> </newnode> T:\ftemp>type rowan.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes"/>
<xsl:template match="/"> <xsl:variable name="pass1"> <xsl:call-template name="next-level"> <xsl:with-param name="level" select="0"/> <xsl:with-param name="nodes" select="//node"/> </xsl:call-template> </xsl:variable> <xsl:apply-templates select="$pass1/node()"/> </xsl:template>
<xsl:template match="*[@id]"> <xsl:copy> <xsl:attribute name="id"> <xsl:number level="any" count="*[@id]"/> </xsl:attribute> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
T:\ftemp>type rowan3.xml <?xml version="1.0" encoding="UTF-8"?> <newnode id="1"> <name>Root of my tree</name> <newnode id="2"> <name>Child of root</name> </newnode> <newnode id="3"> <name>Another child of root</name> <newnode id="4"> <name>Grandchild of root</name> </newnode> </newnode> <newnode id="5"> <name>Yet another child of root</name> </newnode> </newnode> T:\ftemp>rem Done!
-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Identifier attribute (was, Rowan Sylvester-Brad | Thread | Re: [xsl] Identifier attribute (was, Rowan Sylvester-Brad |
Re: [xsl] Content of Script element, Darcy Parker | Date | Re: [xsl] Content of Script element, David Carlisle |
Month |