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

XSL sorting problem

I have a problem with XSL sorting. The problem is that I need to create
a 2 column table so I am using this.

<xsl:apply-templates select="//Photo[position()mod 2=1]">
</xsl:apply-templates>

With template
<xsl:template match="//Photo">
.....
</xsl:template>

The problem arises when I want to sort the Photos by date (field name
Taken)

I tried this
<xsl:apply-templates select="//Photo[position()mod 2=1]">
<xsl:sort select="Taken"/>
</xsl:apply-templates>

With template
<xsl:template match="//Photo">
.....
</xsl:template>

but as you could see it is sorting the first columns of photos by date
but the second column is not sorted, as the second column is produced
using :
following-sibling::*/XXXXX
When I tried this:
<xsl:apply-templates select="//Photo">
<xsl:sort select="Taken"/>
</xsl:apply-templates>

With template
<xsl:template match="//Photo[position()mod 2=1]">
.....
</xsl:template>

The table is fine but its printing out all of the data from some Photo
nodes at the top of the page.
ie.
181001047_20050627_001.jpgtmb_001047_20050627_001. jpga27/06/2005
12:00:00
AM22001047_20050628_002.jpgtmb_001047_20050628_002 .jpg2planks28/06/2005
12:00:00 AM44001047_20050628_004.jpgtmb_001047_20050628_004 .jpg4
28/06/2005 12:00:00
AM66001047_20050628_006.jpgtmb_001047_20050628_006 .jpg28/06/2005
12:00:00 AM

Can someone tell me how to solve this problem.

Jul 20 '05 #1
11 1447
Anyone?

Jul 20 '05 #2

do it in two stages, first sort then group.
Either as two separate sheets, or using a node-set() extension so you
can do two passes in a single stylesheet (almost every xslt1 engine has
this extension with mozilla's transformiix being the notable exception)
or use xslt2 draft implementation such as saxon8 where node-set() isn't
needed.

David
Jul 20 '05 #3
Although I do not understand completely what you want, it seems to me
like you might want to use some variables. Store in one variable var1
all Photo elements with position() mod2 =1, and in another var2 all
Photo elements with mod 2=0. Then you can sort both of these
node-lists.

If this did not help, try and give me a more concrete example (e.g.,
the original xml, and how you'd like it to look after the
transformation).

Jul 20 '05 #4
xml file
<Photolist>
<Photo>
<ID>1</ID>
<Instance>1</Instance>
<Filename>001046_20050630_001.jpg</Filename>
<Thumbnail>tmb_001046_20050630_001.jpg</Thumbnail>
<Caption>
</Caption>
<Description>
</Description>
<Taken>2005-06-30T00:00:00.0000000+10:00</Taken>
</Photo>
<Photo>
<ID>2</ID>
<Instance>2</Instance>
<Filename>001046_20050630_002.jpg</Filename>
<Thumbnail>tmb_001046_20050630_002.jpg</Thumbnail>
<Caption>
</Caption>
<Description>
</Description>
<Taken>2005-06-30T00:00:00.0000000+10:00</Taken>
</Photo>
.....

I want the transformation to be a HTML file that forms a thumnail
gallery, a table with 2 columns. The thumbnails should be order from
the latest "Taken" at the top row.
Ie.
<html>..

<table>
<tr><td>thumbnail1</td><td>thumbnail2</td></tr>
<tr><td>thumbnail3</td><td>thumbnail4</td></tr>
<tr><td>thumbnail5</td><td>thumbnail6</td></tr>
</table>
Thanks

Jul 20 '05 #5
OK, try the following:

1.) sort all thumbnails by date and store them in a variable (e.g.
"sorted")
2.) select the first, third etc. as you did above by using mod 2 = 1,
but from $sorted instead of the original document, and store the
result in another variable ("uneven")
3.) select the second, fouth etc. thumbnail by using mod 2 = 0 on
$sorted, store in ("even")
4.) Use a for-each on "uneven" and construct you table rows.
5.) Watch out for the last row ... it might not contain an element in
"$even"

There might be a more elegant way, but I could not come up with one.
But this should work ;-)

Jul 20 '05 #6
I am having a problem with no.4. as I don't how to place even & odd
photos side by side in a table row. As its easy to create a row of just
evenphotos but how do I get the odd into it?

Jul 20 '05 #7
I am also having problems with getting nodes sorted into a variable.

I tried this
<xsl:for-each select="//Photolist">
<xsl:sort select="Taken"/>
<xsl:variable name="sorted" select="//Photo" />
</xsl:fore-each>

But it doesn't sort it.

Jul 20 '05 #8
re***@hotmail.com writes:
I am also having problems with getting nodes sorted into a variable.

I tried this
<xsl:for-each select="//Photolist">
<xsl:sort select="Taken"/>
<xsl:variable name="sorted" select="//Photo" />
</xsl:for-each>

But it doesn't sort it.


In the above the variable would go out of scope after the for-each so it
could not be used, but in general Variables hold node sets, and sets 9as
opposed to lists or sequences) are always unordered. You can not hold an
ordering in XSLt1 you can only affect the order in which the processing
occirs using xsl:sort.

David
Jul 20 '05 #9
Would it be possible if you can show me a simple example as how to do
it.

Jul 20 '05 #10
Hi,

I'm sorry, I couldn't figure it out myself. Seems that it doesn't work
the way I thought it should.

Unfortunately, you'll need to find another way I do not yet see ...
Sorry I couldn't help solve your problem.

Jul 20 '05 #11
Its amazing my first attempt at XML/XSL, and I can stump it. I think
its better to stick to a "real" language when it comes to real world
sorting of data as XML/XSL is only viable for very simple data
processing.

ja******@gmx.de wrote:
Hi,

I'm sorry, I couldn't figure it out myself. Seems that it doesn't work
the way I thought it should.

Unfortunately, you'll need to find another way I do not yet see ...
Sorry I couldn't help solve your problem.


Jul 20 '05 #12

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

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
9
by: jwedel_stolo | last post by:
Hi I'm creating a dataview "on the fly" in order to sort some data prior to writing out the information to a MS SQL table I have used two methods in order to determine the sort order of the...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
4
by: John Bullock | last post by:
Hello, I am at wit's end with an array sorting problem. I have a simple table-sorting function which must, at times, sort on columns that include entries with nothing but a space (@nbsp;). I...
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...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
1
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
7
Plater
by: Plater | last post by:
I am having trouble determining when my DataGridView object is sorting (based on a column header click). The idea is, in a large table, sorting the columns takes time, so I show a splash screen....
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: 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
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
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...

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.