473,326 Members | 2,136 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,326 software developers and data experts.

sorting <xsl:for-each> versus <xsl:apply-templates>

My Xml is as follows;
<root>
<st id="1">
<rt id="1">
<cr id="1" ca_w="" ca_x="" ca_y="" ca_z="" other attribs>
<ct some attribs>
<te some attribs />
<te some attribs />
<te some attribs />
<te some attribs />
</ct>
<cr id="1" ca_w="" ca_x="" ca_y="" ca_z="" other attribs>
<ct some attribs>
<te some attribs />
<te some attribs />
<te some attribs />
<te some attribs />
</ct>
</cr>
<cr id="1" ca_w="" ca_x="" ca_y="" ca_z="" other attribs>
<ct some attribs>
<te some attribs />
<te some attribs />
<te some attribs />
<te some attribs />
</ct>
</cr>
</rt>
<rt id="2">
<cr id="1" ca_a="" ca_b="" ca_c="" ca_d="" other attribs>
<ct some attribs>
<te some attribs />
<te some attribs />
<te some attribs />
<te some attribs />
</ct>
<cr id="1" ca_a="" ca_b="" ca_c="" ca_d="" other attribs>
<ct some attribs>
<te some attribs />
<te some attribs />
<te some attribs />
<te some attribs />
</ct>
</cr>
<cr id="1" ca_a="" ca_b="" ca_c="" ca_d="" other attribs>
<ct some attribs>
<te some attribs />
<te some attribs />
<te some attribs />
<te some attribs />
</ct>
</cr>
</rt>
</st>


I have written a recursive xslt template to iterate down the nodes and
produce a "tree" like output. I have used the xsl axis [child::*],
calling the template again within a for-each loop. I want to achieve
sorting on the "cr" nodes' ca_ attributes and as can be seen the
attributes change depending upon the st/rt xml sections. Therefore the
sort criteria needs to change from one section of the xml to another.
I'm not too sure this can be achieved due to the way I am processing
the document. I tried to use a sort key such as below, which didn't
work.

st[@id=1]/rt[@id=1]/cr/@ca_x

When just specifying @ca_x or @ca_y, when the xslt processor reaches
the first set of cr nodes it sorts it correctly, the only problem
being that I have no way of changing the sort criteria when it reaches
the next st/rt section. I have a feeling I should perhaps be
processing each st/rt section using the apply-templates element
therefore allowing me to specify different sort criteria for each. I
am not too sure how the apply-templates works if you want to process
the whole of a dynamic xml document, i.e if I'm not sure at processing
time how many st/rt sections there will be, the for-each seems the
only way I can process everything? I would be grateful for any advice.

Regards,

Sparko.
Jul 20 '05 #1
0 1659

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

Similar topics

1
by: andrew_nuss | last post by:
Hi, Something mysterious has happened to my stylus studio project as I've added changes to the XSL file that renders html output. Before, the output included the <HEADand <BODYtags for the HTML...
8
by: ismailc | last post by:
Hi, I would like to change the text color of (<xsl:value-of select="Description") onmouseover of image. the javascript works, it's just that i can seem to get the name correct <td>...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.