Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic query string in XSL not working

Status
Not open for further replies.

csbdeady

Programmer
May 18, 2002
119
0
0
GB
Hi

I have successfully passed in the variable sortorder from my PHP program to an XSL stylesheet.

However I cannot display it within the following:
Code:
<xsl:stylesheet version = '1.0'
xmlns:xsl='[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform'>[/URL]

<xsl:output method="html" indent="yes"/>

<xsl:param name="sortorder" />
 
<xsl:template match="events">
 <table border="0">
<a href="showevents.html?sortorder={sortorder}">
  <xsl:apply-templates>
  <xsl:sort order="$sortorder" select="concat(substring(startdate, 7,2),substring(startdate, 4,2),substring(startdate, 1,2))" data-type="numeric" /> 
  </xsl:apply-templates>
 </table>
</xsl:template>

<xsl:template match="event">
 <tr>
  <td><a href="showevents.php?eventID={@eventID}"><em class="sm"><xsl:value-of select="name" /></em></a></td><td><em class="gr"><xsl:value-of select="startdate" /></em></td>
 </tr>
</xsl:template>

</xsl:stylesheet>

I've tried using:
{sortorder}
{@sortorder}

and had a go with:
Code:
<xsl:template match="sorting">
  <A HREF="showevents.php?sortorder={sortorder}">
    <em class="sm">[recent 1st]</em>
  </A></xsl:template>

but no luck.

I'm sure this must be straightforward. I would like the HREF to be ouput as HTML thus:
Code:
<a href="showevents.php?sortorder=1">
 
Unfortunately, I don't think you can use parameters for sort order. I haven't had any luck getting them to work. What I have done to achieve this is actually create 2 separate xsl files, and call the appropriate one depending on the querystring. A little bit clunky, but it works.

Hope this helps.
 
You can use parameters for the sort-order as well as the sort-field, even if you cannot do use parameters in the order-attribute itself. Just a little trick:
Code:
<xsl:param name="sortorder" />
<xsl:param name="sortfield" />

<xsl:template match="list">
  <xsl:choose>
    <xsl:when test="$sortorder='desc'">
      <xsl:call-template name="sortedlistdesc" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:call-template name="sortedlistasc" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="sortedlistdesc">
  <xsl:for-each select="*">
    <xsl:sort select="*[name()=$sortfield]" order="descending" />
    <xsl:apply-templates select="." />
  </xsl:for-each>
</xsl:template>

<xsl:template name="sortedlistasc">
  <xsl:for-each select="*">
    <xsl:sort select="*[name()=$sortfield]" order="ascending" />
    <xsl:apply-templates select="." />
  </xsl:for-each>
</xsl:template>

<xsl:template match="listitem">
   ...
</xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top