|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Yet another grouping question
An XSLT 2.0 solution:
<xsl:template match="/">
<index>
<xsl:for-each-group select="indexRoot/indexItem"
group-by="@primary">
<primary name="{@primary}">
<xsl:for-each select="current-group()[@secondary]">
<secondary name="{@secondary}"/>
</xsl:for-each>
</primary>
</xsl:for-each-group>
</index>
</xsl:template>
No keys or generate-id() in sight :)
cheers
andrew
> 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.
>
> Imagine I have an XML file like this:
>
> <indexRoot>
> <indexItem primary="ide" secondary="object repository"/>
> <indexItem primary="ide" secondary="Project Manager"/>
> <indexItem primary="ide" secondary="Code Editor"/>
> <indexItem primary="projects" secondary="type of"/>
> <indexItem primary="projects" secondary="additional projects"/>
> <indexItem primary="unmanaged code"/>
> </indexRoot>
>
>
> I would like to group it something like:
>
>
> <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"/>
> </index>
>
> I have defined a key like this:
>
> <xsl:key name="index-by-primary" match="indexItem"
> use="@secondary" />
>
> When I try to get the first with something like:
>
> <xsl:for-each select="indexItem[count(. | key('index-by-primary',
> @primary)[1]) = 1]">
> <xsl:message>
> <xsl:value-of select="@primary"/>, <xsl:value-of
> select="@secondary"/>
> </xsl:message>
> </xsl:for-each>
>
> I get a message for every indexItem, not just the first of
> each unique @secondary.
|
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








