[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Re: [xsl 1.0] howto merge branches by name
Sorry, I didn't finish my critique of your approach.
At 2011-12-14 22:37 +0200, Adrian Herscu wrote: <xsl:template match="suite"> Your problem is in your key lookup above: you are looking at each case with its respective suite parent, rather than the unique suite parent that was determined in the previous step. The processor is finding multiple occurrences of the first of a case within its parent, rather than the first of a case in all parents of the same suite attribute. Below is your code modified only to fix the above, and then my version of your code. Again, I'm guessing at your input content. And I'm assuming you aren't trying to group unique procedures by their attribute. I hope this helps. . . . . . . . . . Ken p.s. please forgive me for misreading the original subject line that indicated you were working with XSLT 1.0
t:\ftemp>call xslt adrian.xml adrian-modified.xsl <?xml version="1.0" encoding="utf-8"?> <test> <suite name="A"> <case name="A"> <procedure name="A"/> <procedure name="B"/> </case> <case name="B"> <procedure name="A"/> </case> </suite> <suite name="C"> <case name="A"> <procedure name="A"/> <procedure name="B"/> </case> <case name="B"> <procedure name="A"/> </case> </suite> </test> t:\ftemp>call xslt adrian.xml adrian-ken.xsl <?xml version="1.0" encoding="utf-8"?> <test> <suite name="A"> <case name="A"> <procedure name="A"/> <procedure name="B"/> </case> <case name="B"> <procedure name="A"/> </case> </suite> <suite name="C"> <case name="A"> <procedure name="A"/> <procedure name="B"/> </case> <case name="B"> <procedure name="A"/> </case> </suite> </test> t:\ftemp>type adrian-modified.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:key name="suites" match="//suite" use="@name" /> <xsl:key name="cases" match="//case" use="concat(../@name, '.', @name)" /> <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template match="test"> <test> <xsl:for-each select="//suite"> <xsl:if test="generate-id() = generate-id(key('suites',@name)[1])"> <xsl:apply-templates select="." /> </xsl:if> </xsl:for-each> </test> </xsl:template> <xsl:template match="suite"> <suite name="{@name}"> <xsl:variable name="suite-name" select="@name"/> <xsl:for-each select="//case"> <xsl:if test="generate-id() = generate-id(key('cases',concat($suite-name, '.', @name))[1])"> <xsl:apply-templates select="." /> </xsl:if> </xsl:for-each> </suite> </xsl:template> <xsl:template match="case"> <case name="{@name}"> <xsl:copy-of select="key('cases',concat(../@name, '.', @name))/ procedure"/> </case> </xsl:template> </xsl:stylesheet> t:\ftemp>type adrian-ken.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:key name="suites" match="suite" use="@name" /> <xsl:key name="cases" match="case" use="concat(../@name, '
', @name)" /> <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template match="test"> <test> <xsl:apply-templates select="suite[generate-id() = generate-id(key('suites',@name)[1])]"/> </test> </xsl:template> <xsl:template match="suite"> <suite name="{@name}"> <xsl:variable name="suite-name" select="@name"/> <xsl:apply-templates select="//case[generate-id() = generate-id(key('cases',concat($suite-name, '
', @name))[1])]"/> </suite> </xsl:template> <xsl:template match="case"> <case name="{@name}"> <xsl:copy-of select="key('cases',concat(../@name, '
', @name))/ procedure"/> </case> </xsl:template> </xsl:stylesheet> t:\ftemp> -- Contact us for world-wide XML consulting and instructor-led training Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0 http://ude.my/uoui9h Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|
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
|