473,414 Members | 1,716 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,414 software developers and data experts.

sorting XML by multiple elements

R
Hi All,

I have problem with sorting nodes I want sort them by columns c1, c2
also I have node <root><sort ActiveField="c0"/></root>

ActiveField attribute is set by user.

I'm sorting 'row' nodes, 'row' has c0, c1, c2, ..., cn child elements

I wrote:
<xsl:for-each select="row">
<xsl:sort select="concat(/root/sort/@ActiveField, c1, c2)"/>
// do somethning
</xsl:for-each>

but I doesn't work - is it allowed to use XPath inside concat function?

how can it be achived to sort 'row' elements by multiple elements?

thanks in advance for any help
best regards
R

May 30 '06 #1
4 1442


R wrote:

<xsl:for-each select="row">
<xsl:sort select="concat(/root/sort/@ActiveField, c1, c2)"/>
// do somethning
</xsl:for-each>

but I doesn't work - is it allowed to use XPath inside concat function?

how can it be achived to sort 'row' elements by multiple elements?


You can have multiple xsl:sort elements inside the xsl:for-each e.g.
<xsl:for-each select="row">
<xsl:sort select="c1" />
<xsl:sort select="c2" />
<!-- ... -->
</xsl:for-each>

--

Martin Honnen
http://JavaScript.FAQTs.com/
May 30 '06 #2
R
thanks,

If you could help me out with XPath expression in xsl:sort

given
<root><sort ActiveField="name"/></root>

<xsl:for-each select="row">
<xsl:sort select="/root/sort/@ActiveField" />
<xsl:sort select="c1" />
<xsl:sort select="c2" />
<!-- ... -->
</xsl:for-each>

doesn't work - probably in place of /root/sort/@ActiveField string
'name' is passed
so every row is sorted by conts 'name' (not value of name element)
and values of c1 and c2 elements

when I hardcode the child element this way:

<xsl:for-each select="row">
<xsl:sort select="name" />
<xsl:sort select="c1" />
<xsl:sort select="c2" />
<!-- ... -->
</xsl:for-each>

it works fine - how can the same result be achieved with
/root/sort/@ActiveField attribute
pointing to the name of the first sort element?

thanks in advance for any hints
best regards
R

May 30 '06 #3
R
sorry i've just found the solution:

<xsl:sort select="*[name() = /root/sort/@ActiveField]"/>

;)

best regards
R

May 30 '06 #4


R wrote:

If you could help me out with XPath expression in xsl:sort

given
<root><sort ActiveField="name"/></root>

<xsl:for-each select="row">
<xsl:sort select="/root/sort/@ActiveField" />


I think you want
<xsl:sort select="*[local-name() = /root/sort/@ActiveField]" />

--

Martin Honnen
http://JavaScript.FAQTs.com/
May 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dennis Gearon | last post by:
This is what has to be eventually done:(as sybase, and probably others do it) http://www.ianywhere.com/whitepapers/unicode.html I'm not sure how that will affect LIKE and REGEX. ...
2
by: Gernot Frisch | last post by:
Hi, I know I can give a std::map a sorting function in the c'tor. However, I would need to _change_ the sorting behaviour of an existing instance. How would I do that? Thank you, --
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
9
by: Daz | last post by:
Hello people! (This post is best viewed using a monospace font). I need to create a class, which holds 4 elements: std::string ItemName int Calories int Weight int Density
4
by: rushik | last post by:
Hello all, I am using structure in my program, and my aim is to sort this structure based on some optimized sorting algo. structure is struct data { int account;
77
by: arnuld | last post by:
1st I think of creating an array of pointers of size 100 as this is the maximum input I intend to take. I can create a fixed size array but in the end I want my array to expand at run-time to fit...
1
by: arnuld | last post by:
On Mon, 29 Sep 2008 15:16:56 +0100, Ben Bacarisse wrote: An abstract overview of my own program by Ben had helped me focus on the design issue first. I came to know that whole problem went...
2
by: felciano | last post by:
Hello -- I am trying to use XSL to process Amazon wishlist data to sort the results by type (Apparel, then Books, then DVDs, etc). Amazon's web services chunk up results in multiple pages of...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.