[xsl] Sending parameters to XSL stylsheet

Subject: [xsl] Sending parameters to XSL stylsheet
From: "Daniel J. Stahl" <ds2xa@xxxxxxxxxxxx>
Date: Fri, 30 May 2003 10:13:49 -0400

I have a newbie question, but I hope you'll bear with me.  I'm
attempting to send a parameter to an XSL stylesheet.  This parameter is
designed to provide a variable to the xsl:sort function so that it can
correctly sort the XML data based on last name.

My code snippit looks like this:

 <td><a href="combined.asp?sortBy=lname">Last Name</a></td>  'this code
sends the parameter 'lname' to an .asp page

The .asp page calls the stylesheet and the stylesheet contains the usual
header information and the following parameter

         <xsl:stylesheet version="1.0"

         <xsl:param name="sortBy"/>    
          <xsl:output method="html"/>  ...	

Later in the stylesheet I try to use the sortBy parameter in the
following manner:

<xsl:sort select="name/$sortBy" data-type="text" order="ascending"/>

But I get the following dreaded error: NodeTest expected here.

If I hard code the sort select statement to say name/lname it works
fine.  But I want to be able to send the stylesheet any number of ways
to sort via parameter passing.

I also tried to capture the entire path statement as the parameter as
shown below: 

<td><a href="combined.asp?sortBy=name/lname">Last Name</a></td>  'this
code sends the parameter lname to an .asp page
      and the code on the style sheet is:
<xsl:sort select="$sortBy" data-type="text" order="ascending"/>

      The good news here is that the code does not produce the 'NodeTest
expected here.' error and will display the stylesheet, but does not sort
it.  The XML data appears in the order of its original input.

What causes this Nodetest error?  Can anyone show me how to produce code
that will prevent it?

Thank you very much

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread