|
|
 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

July 1st, 2008, 12:26 AM
|
|
Registered User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorting some nodes by attribute value
Helow all,
Does anyone know a way to sort on elements by attribute values, except for 1 or two elements, where I want them to stay in the order they already are in?
For example I need to sort all QC nodes in alpha order by @Name attribute, except for categories "Support" and "Support Tools", where I want "Support Tools before Support".
<QC @Name='Instructor'>
<QC @Name='Comments'>
<QC @Name='Job Impact'>
<QC @Name='Support>
<QC @Name='Support Tools'>
I'm trying this so far, but not getting what I want
<xsl:variable name="sortfield">Support Tools</xsl:variable>
<xsl:apply-templates select="//QC" mode="OverallCats">
<xsl:sort select="@*[name(.) = $sortfield]" data-type="string" order="ascending" />
Thanks in advance for the help,
ACW274
|

July 1st, 2008, 02:51 AM
|
|
Authorized User
|
|
Join Date: May 2008
Location: Moscow, , Russia.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
your requirments are not very clear about this ascending/descending variations.
Can you specify what result are you expecting on the following data input:
Code:
<QC Name="Instructor"/>
<QC Name="Comments"/>
<QC Name="Job Impact"/>
<QC Name="Support"/>
<QC Name="Supprot Not Tools"/>
<QC Name="Support Tools"/>
<QC Name="Z"/>
|

July 1st, 2008, 09:07 AM
|
|
Registered User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
I want the results (string datatype as @Name is straight text) in ascending order.
Further information for you though below.
All <QC> nodes have children like below, but I want all QC nodes sorted in alpha ascending order except I want Support Tools before Support as Support Tools has FTID=1 and Support has FTID=2
So, those two I want sorted in ascending order (number datatype) by @FTID and all the rest bye @Name (datatype of string)
<QC Name="Comments">
<Q>
<A>
<FT @FTID =1/>
<FT @FTID =2/>
<FT @FTID =3/>
</A>
</Q>
</QC>
<QC Name="Instructor">
<Q>
<A>
<FT @FTID =1/>
<FT @FTID =2/>
<FT @FTID =3/>
</A>
</Q>
</QC>
<QC Name="Job Impact">
<Q>
<A>
<FT @FTID =1/>
<FT @FTID =2/>
<FT @FTID =3/>
</A>
</Q>
</QC>
<QC Name="Support">
<Q>
<A>
<FT @FTID =2>
</A>
</Q>
</QC>
<QC Name="Support Tools">
<Q>
<A>
<FT @FTID =1>
</A>
</Q>
</QC>
I want the following results:
Comments
Instructor
Job Impact
Support Tools
Support
Thanks in advance for your help
ACW274
|

July 1st, 2008, 10:48 AM
|
|
Authorized User
|
|
Join Date: May 2008
Location: Moscow, , Russia.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<root>
<xsl:apply-templates select="QC">
<xsl:sort select="Q/A/FT/@FTID" order="ascending"/>
<xsl:sort select="name()" order="ascending"/>
</xsl:apply-templates>
</root>
</xsl:template>
<xsl:template match="QC">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
|

July 1st, 2008, 11:52 PM
|
|
Registered User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This worked for you. It did not work for me.
All QC nodes came in @FTID order, but I only want Support Tools and Support to come in @FTID, the other QC nodes to come in alpha order by @Name.
Thanks,
|

July 2nd, 2008, 12:19 AM
|
|
Authorized User
|
|
Join Date: May 2008
Location: Moscow, , Russia.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
quote:It did not work for me.
|
please, provide sample input data that you faced problems with.
on input data you provided before - the result is as you wished.
PS
to make it clear - please, provide the expected output for the following input data:
Code:
<root>
<QC Name="Support">
<Q>
<A>
<FT FTID="2"/>
</A>
</Q>
</QC>
<QC Name="Support AAA">
<Q>
<A>
<FT FTID="1"/>
<FT FTID="2"/>
<FT FTID="3"/>
</A>
</Q>
</QC>
<QC Name="Support Tools">
<Q>
<A>
<FT FTID="1"/>
</A>
</Q>
</QC>
</root>
|

July 2nd, 2008, 01:00 AM
|
|
Registered User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The following document order comes in as @FTID order for all QC nodes but I only want Support Tools before Support, and the rest in alpha order by @Namee
<QC Name="Instructor">
<Q>
<A>
<FT @FTID =2/>
<FT @FTID =3/>
</A>
</Q>
</QC>
<QC Name="Comments">
<Q>
<A>
<FT @FTID =1/>
<FT @FTID =2/>
</A>
</Q>
</QC>
<QC Name="Business Results">
<Q>
<A>
<FT @FTID =1/>
</A>
</Q>
</QC>
<QC Name="Job Impact">
<Q>
<A>
<FT @FTID =2>
</A>
</Q>
</QC>
<QC Name="Support">
<Q>
<A>
<FT @FTID =1>
</A>
</Q>
</QC
<QC Name="Support Tools">
<Q>
<A>
<FT @FTID =1>
</A>
</Q>
</QC>
This is the desired output:
Business Results
Comments
Instructor
Job Impact
Support Tools
Support
-----------------------
Not this:
Instructor
Support Tools
Comments
Business Results
Job Impact
Support
|

July 2nd, 2008, 02:11 AM
|
|
Authorized User
|
|
Join Date: May 2008
Location: Moscow, , Russia.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Please, give the desired output for the input I mentioned in my last post.
PS
in your last post
Code:
...
<QC Name="Support">
<Q>
<A>
<FT @FTID =1>
</A>
</Q>
</QC
<QC Name="Support Tools">
<Q>
<A>
<FT @FTID =1>
</A>
</Q>
</QC>
@FTID have the same value for both: 'Support' and 'Support Tools', so why 'Support Tools' should appear first?
|

July 2nd, 2008, 02:22 AM
|
|
Authorized User
|
|
Join Date: May 2008
Location: Moscow, , Russia.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
probably you're looking for smth like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<root>
<xsl:apply-templates select="QC">
<xsl:sort select="substring(@Name,1,7)" order="ascending"/>
<xsl:sort select="Q/A/FT/@FTID" order="ascending"/>
</xsl:apply-templates>
</root>
</xsl:template>
<xsl:template match="QC">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
but it's only a guess
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |