Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 30th, 2007, 05:10 AM
Authorized User
 
Join Date: Mar 2007
Location: Seattle, , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

Reply With Quote
  #2 (permalink)  
Old March 30th, 2007, 10:09 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Try changing:
†<xsl:sort select="STRING" data-type="number" order="descending"/>
to:
†<xsl:sort select="value" order="descending"/>
Reply With Quote
  #3 (permalink)  
Old March 30th, 2007, 01:14 PM
Authorized User
 
Join Date: Mar 2007
Location: Seattle, , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

Reply With Quote
  #4 (permalink)  
Old March 30th, 2007, 06:34 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

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>
Reply With Quote
  #5 (permalink)  
Old March 30th, 2007, 09:45 PM
Authorized User
 
Join Date: Mar 2007
Location: Seattle, , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>

-----------------------------------------------------------------------------------------------------------------------------

Reply With Quote
  #6 (permalink)  
Old March 30th, 2007, 10:16 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

I would suggest to use grouping.



Reply With Quote
  #7 (permalink)  
Old March 31st, 2007, 12:23 AM
Authorized User
 
Join Date: Mar 2007
Location: Seattle, , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Any chance at all you could provide a little more guidance? I'm not sure how to do grouping...

Reply With Quote
  #8 (permalink)  
Old March 31st, 2007, 07:43 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

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?
Reply With Quote
  #9 (permalink)  
Old March 31st, 2007, 04:00 PM
Authorized User
 
Join Date: Mar 2007
Location: Seattle, , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #10 (permalink)  
Old March 31st, 2007, 05:46 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

the top of your xslt, will say tell you what version e.g.

<xsl:stylesheet version="1.0"

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
A simple Sorting question bonekrusher XSLT 2 November 25th, 2007 09:40 AM
Question regarding the display of <a> tags in xml tajjyarden XSLT 1 March 21st, 2007 12:54 PM
Data View Sorting Question jazzcatone ASP.NET 1.0 and 1.1 Basics 0 October 3rd, 2006 10:42 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 02:20 AM
HELP! More complicate sorting nodes question kevin_in_black XSLT 2 April 13th, 2004 06:51 AM



All times are GMT -4. The time now is 03:19 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.