Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Double sort xslt

From: dmessenger@----------.--- (------- ---------)
To: 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 ?


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent