Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Grouping sets of tags with XSLT [Thread Next] Re: Grouping sets of tags with XSLTTo: NULL Date: 9/2/2005 1:22:00 PM masonmarc@y... a écrit :
> So I need to do grouping. I've used the key and generate-id trick to
> do:
>
> <xsl:key name="rs" match="r" use="@comp">
>
> then:
>
> <xsl:for-each select="r[generate-id(.)=generate-id(key('rs',
> @comp)[1])]">
>
> to select the r elements and then process them to get the correct
> output. Using this method I can get the first phone element to output
> correctly, but when it gets to the second one (or any other one that
> has an r element with a comp attribute that has already been processed,
> the select in the for-each statement doesn't select anything (comp="1"
> was already processed in the previous phone element), so I get no
> output. Does anyone have any ideas on how to get this to work or
> another way to do it?
I think you could avoid using xsl:key with something like:
<xsl:template match="phone">
<phone>
<xsl:copy-of select="number" />
<xsl:for-each select="r[not(*)]">
<xsl:variable name="nbr" select="@comp" />
<r comp="{$nbr}">
<r address="{ ../r[@comp="$nbr"]/r/@address }" />
<r country="{ ../r[@comp="$nbr"]/r/@country }" />
</r>
</xsl:for-each>
</phone>
</xsl:template
not tested at all !
HTH,
SL
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
