473,398 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

XSL:Sort parameters

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
2 1530
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jarle Presttun | last post by:
Hi, Sometimes I display values by combining information from different sections in the xml, like I do with gradeText in the student template bellow. Is it possible to sort on gradeText when I...
1
by: Derek Tinney | last post by:
Hi, I'm having difficulty building an XLST file that allows me to sort a list of log records. I put together an XSL file that allows me to output a copy of the input file and then I attempted...
3
by: Tjerk Wolterink | last post by:
I posted my problem earlier, but i simplified the examples, and i know what the cause of the problem is, but i dont know the solution, my xml file: <?xml version="1.0" encoding="ISO-8859-1"?>...
6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
2
by: jobooker | last post by:
I'm having issues sorting. The short description is, how do I set the select attribute of xsl:sort to be the value of an xsl:variable? The longer description follows: What I want to do is to be...
3
by: davisford | last post by:
Hi, If I have something like this: <parents> <parent name="foo"> <children> <child>fred</child> <child>barney</child> <child>wilma</child>
2
by: ajc308 | last post by:
I have an XML document that looks like the following: <root name="PlanRepository"> <directory name="connoraj"> <directory name="single_run1"> <file>insidebox.txt</file> ...
1
by: =?Utf-8?B?SWxsdXN0cmlz?= | last post by:
I'm hoping someone can help me with what looks like a very simple problem. My output does not sort the languages alphabetically as I would expect. Can someone inspect my XSLT please? TIA!! ...
7
by: otis | last post by:
Hi all, This is a small issue to make things prettier, but we all know how important that can be! I had an xsl:if to check if a node was the last one in a collection of nodes and if it was a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.