Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Double sort xslt Double sort xsltTo: NULL Date: 7/22/2004 6:09:00 AM Lets say I have the following:
<Products>
<Product id="123">
<Name>Something</Name>
<Variant>
<Color>Yellow</Color>
<Price>12.99</Price>
</Variant>
<Variant>
<Color>Red</Color>
<Price>11.99</Price>
</Variant>
</Product>
<Product id="124">
<Name>Something Else</Name>
<Variant>
<Color>Yellow</Color>
<Price>12.99</Price>
</Variant>
<Variant>
<Color>Red</Color>
<Price>10.99</Price>
</Variant>
</Product>
</Products>
...and I want to sort them so that
i) the variants are in ascending price order within each product,
and
ii) products are in ascending lowest price order within Products
how do I do this?
I have the following XSLT
<xsl:template match="/">
<Products>
<xsl:variable name="SortedProducts">
<xsl:for-each select="Products/Product">
<xsl:element name="Product">
<xsl:attribute name="id"><xsl:value-of
select="@id"/></xsl:attribute>
<xsl:for-each select="Variant">
<xsl:sort select="Price" data-type="number"/>
<xsl:copy-of select="."/>
</xsl:for-each>
<xsl:for-each select="*[not(Variant)]"><xsl:copy-of
select="."/></xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="exsl:node-set($SortedProducts)/Product">
<xsl:sort select="Price" data-type="number"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</Products>
</xsl:template>
This results in two copies of the variants being generated. If I place
the for-each for *[not(Variant)] before the Variant copy, it doesn't
get sorted, but at least I only get one copy.
If I remove the *[not(Variant)] the sorting is correct but the other
elements are, of course, missing.
How do I go about copying and double sorting ?
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
