Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problems parameterizing xsl:sort

0 views
Skip to first unread message

Paul Harding

unread,
Nov 19, 2001, 2:46:47 PM11/19/01
to
I'm using JAXP and Xalan to process my XML into html. I have a number of
rows that I would like to sort by a user selected column.
I pass the name of the column to sort by to my xslt from servlet and save it
as a parameter:

<xsl:param name="sort"/>

I then try to sort using this parameter, but it never recognizes the
parameters value:

<table width="1200" class="details" border="0">
<xsl:call-template name="columnHeaders"/>
<xsl:for-each select="$features">
<xsl:sort select="$sort"/> <!-- tried lots of variations here - doesn't
like {$sort}
<tr >
<xsl:call-template name="processFeatureAttr">
<xsl:with-param name="field" select="."/>
</xsl:call-template>
</tr>
</xsl:for-each>
</table>

but if I hard code the sort select value, like select ="owner", all works
well.

If it try something more brute force where I explicitly compare the value of
the parameter,

<xsl:choose>
<xsl:when test="$sort==owner"> \
<xsl:text>tested sort for owner </xsl:text><xsl:value-of select="$sort"/>

</xsl:when>
</xsl:choose>


it never works - gets assertion failure in the parser

any ideas on how best to parameterize the sort/select value?
how does one compare a parameter for an explicit value?

--
Cheers,

Paul Harding
Algorithmics Inc.
phar...@algorithmics.com 189 Spadina Ave.
(voice) 416-217-4431 Toronto, Ont. M5T 2C6
(fax) 416-971-6100

--
Cheers,

Paul Harding
Principal Software Engineer Algorithmics Inc.
phar...@algorithmics.com 189 Spadina Ave.
(voice) 416-217-4431 Toronto, Ont. M5T 2C6
(fax) 416-971-6100

Tuija Sonkkila

unread,
Nov 21, 2001, 6:12:03 AM11/21/01
to
Paul Harding <phar...@algorithmics.com> wrote:
> any ideas on how best to parameterize the sort/select value?

There is no direct way. But if the sort key is a child element of the
elements you want to sort, as in your case, you could say:

<xsl:sort select="*[local-name()=$sort]"/>

> how does one compare a parameter for an explicit value?

<xsl:when test="$sort = 'owner'">
...
</xsl:when>

This assumes that the value of your parameter really is a string.

Hope this helps,

Tuija

--
Tuija Sonkkila
HUT CC

Paul Harding

unread,
Nov 21, 2001, 4:35:14 PM11/21/01
to
>
> There is no direct way. But if the sort key is a child element of the
> elements you want to sort, as in your case, you could say:
>
> <xsl:sort select="*[local-name()=$sort]"/>

works like a charm
many thanx
pharding


0 new messages