K
kristofera
I am trying to do a distinct grouping of some nodes sorted by a numeric
value but for some reason the distinct (preceding-sibling filter) is
applied to the result as if not sorted. If I don't use the
preceding-sibling filter, the nodes are properly sorted. Is this a bug
in the xslt processor I'm using (.net framework 1.1) or is this correct
behaviour?
Any alternative solutions that will show me the lowest priced item in
each category? (xml and xslt snippets below)
XML:
<Items>
<Item>
<ItemCategory>Cat A</ItemCategory>
<ItemName>Item 1</ItemName>
<Price>5</Price>
</Item>
<Item>
<ItemCategory>Cat B</ItemCategory>
<ItemName>Item 2</ItemName>
<Price>3</Price>
</Item>
<Item>
<ItemCategory>Cat A</ItemCategory>
<ItemName>Item 3</ItemName>
<Price>2</Price>
</Item>
</Items>
XSLT snippets:
<xsl:apply-templates select="Item">
<xsl:sort select="ItemCategory" />
<xsl:sort select="Price" data-type="number" order="ascending" />
</xsl:apply-templates>
<xsl:template match="Item">
<xsl:if test="not(ItemCategory=preceding-sibling::Item/ItemCategory)">
Item: <xsl:value-of select="ItemName" />
Price: <xsl:value-of select="Price" />
</xsl:if>
</xsl:template>
Expected output:
Item: Item 3
Price: 2
Item: Item 2
Price: 3
Actual output:
Item: Item 1
Price: 5
Item: Item 2
Price: 3
value but for some reason the distinct (preceding-sibling filter) is
applied to the result as if not sorted. If I don't use the
preceding-sibling filter, the nodes are properly sorted. Is this a bug
in the xslt processor I'm using (.net framework 1.1) or is this correct
behaviour?
Any alternative solutions that will show me the lowest priced item in
each category? (xml and xslt snippets below)
XML:
<Items>
<Item>
<ItemCategory>Cat A</ItemCategory>
<ItemName>Item 1</ItemName>
<Price>5</Price>
</Item>
<Item>
<ItemCategory>Cat B</ItemCategory>
<ItemName>Item 2</ItemName>
<Price>3</Price>
</Item>
<Item>
<ItemCategory>Cat A</ItemCategory>
<ItemName>Item 3</ItemName>
<Price>2</Price>
</Item>
</Items>
XSLT snippets:
<xsl:apply-templates select="Item">
<xsl:sort select="ItemCategory" />
<xsl:sort select="Price" data-type="number" order="ascending" />
</xsl:apply-templates>
<xsl:template match="Item">
<xsl:if test="not(ItemCategory=preceding-sibling::Item/ItemCategory)">
Item: <xsl:value-of select="ItemName" />
Price: <xsl:value-of select="Price" />
</xsl:if>
</xsl:template>
Expected output:
Item: Item 3
Price: 2
Item: Item 2
Price: 3
Actual output:
Item: Item 1
Price: 5
Item: Item 2
Price: 3