 |
| 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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 30th, 2007, 04:10 AM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorting on similar tags question
Hi everyone,
I'm new to XSLT and was wondering if someone could help me with this problem? This is a snippet XML I'm dealing with ->
<fact>
<name>MAIN::SNPRank</name>
<slot>
<name>id</name>
<value type='STRING'>rs13266634</value>
</slot>
<slot>
<name>rank</name>
<value type='STRING'>0.70</value>
</slot>
<slot>
<name>category</name>
<value type='STRING'>nonsynonymous</value>
</slot>
</fact>
I'm trying to sort the middle "value type='STRING'" value (0.70). I'm using the following XSLT code ->
<xsl:for-each select="fact">
<xsl:if test="name = 'MAIN::SNPRank'">
<tr width="80%" align="center">
<xsl:for-each select="slot">
<xsl:sort select="STRING" data-type="number" order="descending"/>
<td align="center">
<xsl:value-of select="value"/>
</td>
</xsl:for-each>
</tr>
</xsl:if>
</xsl:for-each>
Unfortunately, it doesn't seem to work.
Could anyone please provide some help and guidance?
I'm be most appreciative. Thanks for any responses in advance!
~Terry
|
|

March 30th, 2007, 09:09 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Try changing:
<xsl:sort select="STRING" data-type="number" order="descending"/>
to:
<xsl:sort select="value" order="descending"/>
|
|

March 30th, 2007, 12:14 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks bonekrusher, but that doesn't work. It only sorts on the first <value type='STRING'>rs13266634</value> pair. Not the middle <value type='STRING'>0.70</value> pair.
Could anyone else offer some suggestions?
|
|

March 30th, 2007, 05:34 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
try this... it worked for me:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<xsl:for-each select="fact">
<xsl:if test="name = 'MAIN::SNPRank'">
<tr width="80%" align="center">
<xsl:for-each select="slot">
<xsl:sort select="value" order="ascending"/>
<td align="center">
<xsl:value-of select="value"/>
</td>
</xsl:for-each>
</tr>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
|
|

March 30th, 2007, 08:45 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks again bonekrusher, but it's still not working for me. I used the code you suggested (except I used descending instead so I could have the higher scores at the top of the list). Could you test it again with the following XML? ->
Because I'm getting this result:
rs3740878 intron 0.30
rs11037909 intron 0.30
rs13266634 nonsynonymous 0.60
rs7480010 intron 0.30
rs7903146 intron 0.30
rs1113132 intron 0.30
Instead, I would like to have rs1326634 at the top because it has a score of 0.60.
Again, thanks so much for your help!
----------------------------------------------------------------------------------------------------------------------
<fact>
<name>MAIN::Synonymity</name>
<slot>
<name>type</name>
<value type='STRING'>intron</value>
</slot>
<slot>
<name>rsnum</name>
<value type='STRING'>rs3740878</value>
</slot>
</fact>
<fact>
<name>MAIN::SNPRank</name>
<slot>
<name>id</name>
<value type='STRING'>rs3740878</value>
</slot>
<slot>
<name>rank</name>
<value type='STRING'>0.30</value>
</slot>
<slot>
<name>category</name>
<value type='STRING'>intron</value>
</slot>
</fact>
<fact>
<name>MAIN::Synonymity</name>
<slot>
<name>type</name>
<value type='STRING'>intron</value>
</slot>
<slot>
<name>rsnum</name>
<value type='STRING'>rs11037909</value>
</slot>
</fact>
<fact>
<name>MAIN::SNPRank</name>
<slot>
<name>id</name>
<value type='STRING'>rs11037909</value>
</slot>
<slot>
<name>rank</name>
<value type='STRING'>0.30</value>
</slot>
<slot>
<name>category</name>
<value type='STRING'>intron</value>
</slot>
</fact>
<fact>
<name>MAIN::Synonymity</name>
<slot>
<name>type</name>
<value type='STRING'>coding-nonsynonymous,reference</value>
</slot>
<slot>
<name>rsnum</name>
<value type='STRING'>rs13266634</value>
</slot>
</fact>
<fact>
<name>MAIN::SNPRank</name>
<slot>
<name>id</name>
<value type='STRING'>rs13266634</value>
</slot>
<slot>
<name>rank</name>
<value type='STRING'>0.60</value>
</slot>
<slot>
<name>category</name>
<value type='STRING'>nonsynonymous</value>
</slot>
</fact>
<fact>
<name>MAIN::Synonymity</name>
<slot>
<name>type</name>
<value type='STRING'>intron</value>
</slot>
<slot>
<name>rsnum</name>
<value type='STRING'>rs7480010</value>
</slot>
</fact>
<fact>
<name>MAIN::SNPRank</name>
<slot>
<name>id</name>
<value type='STRING'>rs7480010</value>
</slot>
<slot>
<name>rank</name>
<value type='STRING'>0.30</value>
</slot>
<slot>
<name>category</name>
<value type='STRING'>intron</value>
</slot>
</fact>
<fact>
<name>MAIN::Synonymity</name>
<slot>
<name>type</name>
<value type='STRING'>intron</value>
</slot>
<slot>
<name>rsnum</name>
<value type='STRING'>rs7903146</value>
</slot>
</fact>
<fact>
<name>MAIN::SNPRank</name>
<slot>
<name>id</name>
<value type='STRING'>rs7903146</value>
</slot>
<slot>
<name>rank</name>
<value type='STRING'>0.30</value>
</slot>
<slot>
<name>category</name>
<value type='STRING'>intron</value>
</slot>
</fact>
<fact>
<name>MAIN::Synonymity</name>
<slot>
<name>type</name>
<value type='STRING'>intron</value>
</slot>
<slot>
<name>rsnum</name>
<value type='STRING'>rs1113132</value>
</slot>
</fact>
<fact>
<name>MAIN::SNPRank</name>
<slot>
<name>id</name>
<value type='STRING'>rs1113132</value>
</slot>
<slot>
<name>rank</name>
<value type='STRING'>0.30</value>
</slot>
<slot>
<name>category</name>
<value type='STRING'>intron</value>
</slot>
</fact>
-----------------------------------------------------------------------------------------------------------------------------
|
|

March 30th, 2007, 09:16 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
I would suggest to use grouping.
|
|

March 30th, 2007, 11:23 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Any chance at all you could provide a little more guidance? I'm not sure how to do grouping...
|
|

March 31st, 2007, 06:43 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
The problem seems to be that you are trying to sort by <value>, but the "value" you really want is the numerical value (e.g. 0.60). Then you want to associate the other <values> with in the <fact> element with thay one.
Are you creating the XML or are you forced to use it? Are you using XSLT 1.0 or 2.0?
|
|

March 31st, 2007, 03:00 PM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Unfortunately, I'm forced to work with the XML I have.
I don't know how to check to see if I have XSLT 1.0 or 2.0.
|
|

March 31st, 2007, 04:46 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
the top of your xslt, will say tell you what version e.g.
<xsl:stylesheet version="1.0"
|
|
 |