954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Why doesn't my parameter work in xsl:sort

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?

mulevad
Newbie Poster
9 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

No it's not legal. You're not allowed to pass a parameter inside a . It's only allowed to be used as parameter to the entire stylesheet, or as a child of or .

Instead of doing a , you'll need to convert it into a with the appropriate and 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

iceandrews
Junior Poster
185 posts since May 2010
Reputation Points: 10
Solved Threads: 30
 

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.

mulevad
Newbie Poster
9 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

No problem.

iceandrews
Junior Poster
185 posts since May 2010
Reputation Points: 10
Solved Threads: 30
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You