By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,190 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,190 IT Pros & Developers. It's quick & easy.

XSL:Sort parameters

P: n/a
Hello all,

I'm having a problem with XSL:Sort. I've parameterized it (and use
javascript to populate the parameters, but that part is working fine)..
<xsl:sort select="*[name() = $sort_project_col]" />

The problem is that sometimes $sort_project_col is the name of a child
element (that works fine), but sometimes it is also the name of an
attribute of the current node (an ID tag, for example)..

<project id="i2421">
<foo>bar</foo>
</project>

sorting by "foo" would work, however sorting by "@id" wouldn't. I know
why (the sort expression is evaluating child nodes not grandchild nodes
or attributes or anything else), but I cant figure out a way around it.
I've tried replacing the entire expression like so...

<xsl:sort select="{$sort_project_col}" />

and then setting the parameter to be = *[name() = 'foo']" for when I
want to sort by foo, and then have it = "@id" when I want to sort by
ID, but it doesnt work.

Any suggestions? Thanks.

-Anthony

Mar 18 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
si******@gmail.com wrote:
<xsl:sort select="*[name() = $sort_project_col]" />


Take a look at
http://www.w3.org/TR/1999/REC-xpath-19991116#node-tests
and
http://www.w3.org/TR/1999/REC-xpath-...16#path-abbrev

* is shorthand for child::*, and since the principal node type of the
child axis is Element, this selects all the element children and only them.

If you want to examine the attributes, use attribute::* or its shorthand
equivalent @*.

If you want to look in both places, you need to explicitly say so, eg by
requesting (* | @*). This risks some confusion if the same name might
appear both as element and attribute; you might want to use two
different parameters to test these two cases, setting the one you aren't
using to an illegal value such as "".
WARNING: Testing name() is going to fail badly when dealing with
namespaced documents. If you are ever going to want to deal with those
(and you *will* some day want to), you should write the predicate so it
tests both local-name() and namespace-uri() of the nodes you're trying
to recognize.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 18 '06 #2

P: n/a
Thank you very much Joe, your advice helped me solve my issue...

(* | @*) [name() = '$sort_project_col'] is working well. I will look
further into the namespace issue.

-Anthony

Mar 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.