I am placing xml into a table in html and trying to sort based on a parameter, but my parameter's value is not being used. It uses the string "$sortkey" instead.

Here is an xsl excerpt:

<xsl:for-each select="catalog/cd">
	<xsl:param name ="sortkey" select="country"></xsl:param>
        <xsl:sort select="$sortkey"/>
              <xsl:value-of select="title"/>
              <xsl:value-of select="artist"/>
              <xsl:value-of select="country"/>


If I stick "title" in my sort's select statement I get the results sorted by title.

Is this not legal for some reason?

Recommended Answers

All 3 Replies

No it's not legal. You're not allowed to pass a parameter inside a <xsl:for-each>. It's only allowed to be used as parameter to the entire stylesheet, or as a child of <xsl:template> or <xsl:function>.

Instead of doing a <xsl:for-each>, you'll need to convert it into a <xsl:template> with the appropriate <xsl:xsl:apply-templates> and <xsl:sort> instruction.

I've talked about sorting before in other threads. You should be able to extract all you need from these.


Thanks very much. This was driving me crazy. I couldn't find this in the specification anywhere. I didn't think to look in the for-each, but I will do that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.