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"/>
        <tr>
            <td>
              <xsl:value-of select="title"/>
            </td>
            <td>
              <xsl:value-of select="artist"/>
            </td>
            <td>
              <xsl:value-of select="country"/>
            </td>
            <td>

...etc....

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

Is this not legal for some reason?

Edited 6 Years Ago by mulevad: n/a

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.

http://www.daniweb.com/forums/thread286526.html
http://www.daniweb.com/forums/thread288865.html

Edited 6 Years Ago by iceandrews: n/a

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.

This question has already been answered. Start a new discussion instead.