Ok I've posted a thread on this previously, and got some great help - but requirements have changed and I'm still not able to get this to work correctly. The previous thread has been marked as 'answered' and it seems I can't undo that (or edit posts..) and it's not getting much love anymore.
That's not going to work, as it's grabbing the the values of the first node, not of each node.
I've tried using <xsl:text> tag (instead of xsl:value-of, the idea being, I want to set the xpath(?) statement to be used for the sort itself) but no luck there either.
XSLT Conditional Sorts...
Ok I've posted a thread on this previously, and got some great help - but requirements have changed and I'm still not able to get this to work correctly. The previous thread has been marked as 'answered' and it seems I can't undo that (or edit posts..) and it's not getting much love anymore.
Here's the situation:
<xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
<xsl:sort select="./data [@alias = 'colourCode']" />
This works fine, but I want so that in the presense of a querystring (or similar), it sorts by the @nodeName instead.
You should create a xsl:variable to store your sort parameter with a choose clause
<xsl:variable name="sortParam">
<xsl:choose>
<xsl:when test="TESTFORQUERYSTRING">
<xsl:value-of select="yourquerystringval"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="yournormalval"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:for-each select=".">
<xsl:sort select="$sortParam"/>
...
</xsl:for-each>
I'm doing this wrong.
This is no dice.... (excuse the dodgy conditional logic, was just testing):
That's not going to work, as it's grabbing the the values of the first node, not of each node.
I've tried using <xsl:text> tag (instead of xsl:value-of, the idea being, I want to set the xpath(?) statement to be used for the sort itself) but no luck there either.
Chad I am not entirely sure what you want to do?
So if a querystring is present you want to sort by @nodeName if not you want to sort by the property colourCode ?
Warren
<xsl:variable name="content" select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']" mode="content"/>
<xsl:choose>
<xsl:when test="1=2">
<xsl:apply-templates select="$content">
<xsl:sort select="@nodeName" />
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$content">
<xsl:sort select="@nodeName" />
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="node" mode="content">
<!-- Copy your <xsl:foreach> content here -->
</xsl:template>
hmm forgot to sort by
$currentPage/node/data [@alias = 'colourCode']
in <xsl:otherwise>
(you cannot sort by an variable holding a node-set, just text-strings like data[@alias = $SortParam])
Because you can't use a variable in the select attribute of the xsl:sort element, you'll need to branch out - here's how I'd do it:
/Chriztian
Thanks for everyones help. Finally got it all working!
is working on a reply...