Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old March 30th, 2007, 04:10 AM
Authorized User
 
Join Date: Mar 2007
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

 
Old March 30th, 2007, 09:09 AM
Friend of Wrox
 
Join Date: Jul 2006
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"/>
 
Old March 30th, 2007, 12:14 PM
Authorized User
 
Join Date: Mar 2007
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?

 
Old March 30th, 2007, 05:34 PM
Friend of Wrox
 
Join Date: Jul 2006
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>
 
Old March 30th, 2007, 08:45 PM
Authorized User
 
Join Date: Mar 2007
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>

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

 
Old March 30th, 2007, 09:16 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

I would suggest to use grouping.



 
Old March 30th, 2007, 11:23 PM
Authorized User
 
Join Date: Mar 2007
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...

 
Old March 31st, 2007, 06:43 AM
Friend of Wrox
 
Join Date: Jul 2006
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?
 
Old March 31st, 2007, 03:00 PM
Authorized User
 
Join Date: Mar 2007
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.

 
Old March 31st, 2007, 04:46 PM
Friend of Wrox
 
Join Date: Jul 2006
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"






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 11:54 AM
Data View Sorting Question jazzcatone ASP.NET 1.0 and 1.1 Basics 0 October 3rd, 2006 09:42 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
HELP! More complicate sorting nodes question kevin_in_black XSLT 2 April 13th, 2004 05:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.