Hi am build a generic template to list my content. But the Content may be sorted on different @'s or node()'s. So want to pass the xPath in.
<xsl:variable name="sort" select="@sortBy"/>
<xsl:variable name="order" select="@order"/>
<xsl:for-each select="Content[@type=$contentType]">
<xsl:sort select="$sort" order="{$order}" data-type="text"/>
<xsl:sort select="@update" order="{$order}" data-type="text"/>
<xsl:copy-of select="."/>
</xsl:for-each>
Using a variable to drop in ascending or descending into the order=""
WORKS.
Why cannot do this on the select=""
?
I hoping to make this super dynamic the select variable can be xPtah either @publish or Title/node() or any xPath.
There is no error - It just ignores the sort.
The
|
(union operator) works... I must have gotten it slightly wrong when tried before. It was @Dimitre Novatchev's answer lead me down the right path!!The following works:
It allows me to sort on attributes and nodes. Obviously, as long as they don't have the same
name()
but different values.This is by design. The
select
attribute is the only one which doesnt accept AVTs (Attribute - Value Templates).The usual solution is to define a variable with the name of the child element that should be used as sort key. Below is a small example:
When this transformation is applied on the following XML document:
the wanted result is produced: