|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Yet another grouping question
Hi Shawn,
I have always found grouping to be the most frustrating so I feel your pain... What Jeni and DaveP have done such a great job of is providing a constant reference of tutorials and list content for things like grouping that with consistent reference and study will help you understand how fantastic using the Muenchian (as tough to spell as it can be to understand :) method can be to perform extremely complex transforms... Keep hitting those sites and pick up Dr. Kays book and it will all become clear at some point quite soon... See if the following code makes sense and let me know if you need further help... Really focus on understanding your current context node.. I find breaking your XPath in smaller pieces and checking their values first before trying to compare, match, and apply styles to them accordingly really helps as well... so, this xslt... <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:key name="index-by-primary" match="@primary" use="." /> <xsl:template match="/"> <index> <xsl:apply-templates select="indexRoot/indexItem[generate-id(@primary) = generate-id(key('index-by-primary', @primary))] " mode="level-one"/> </index> </xsl:template> <xsl:template match="indexItem" mode="level-one"> <primary name="{@primary}"> <secondary name="{@secondary}" /> <xsl:apply-templates select="following-sibling::indexItem[@primary = current()/@primary]" mode="level-two" /> </primary> </xsl:template> <xsl:template match="indexItem" mode="level-two">
<secondary name="{@secondary}" />
</xsl:template></xsl:stylesheet> Will give you your desired output of: <?xml version="1.0" encoding="UTF-8"?>
<index>
<primary name="ide">
<secondary name="object repository"/>
<secondary name="Project Manager"/>
<secondary name="Code Editor"/>
</primary>
<primary name="projects">
<secondary name="type of"/>
<secondary name="additional projects"/>
</primary>
<primary name="unmanaged code">
<secondary name=""/>
</primary>
</index>Obviously the last "unmanaged code" doesnt have a secondary attribute but I imagine you can decide how you want to deal with that only applying the second template based on whatever criteria you might have... Best of luck to you! <M:D/> Shawn McKenzie wrote: So I've gone through the 'XSLT Questions and Answers' and Jeni's site and it is still not clear to me why my Muenchien grouping isn't working. Specificaly, the step related to limiting responses to the first in the group.
|
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
|

Cart








