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 31st, 2007, 05:16 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I think bonekrusher has failed to understand your problem.

I think you simply want

<xsl:for-each select="fact">
  <xsl:sort select="slot[name='rank']/@value"
            data-type="number"/>
    ...
</xsl:for-each>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 31st, 2007, 07:33 PM
Authorized User
 
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you, thank you Michael. That seemed to do the trick!

Any chance you could possibly tell me how it worked? Meaning, what does "slot[name='rank']/@value" mean?

Thank you again!

 
Old April 1st, 2007, 03:10 AM
Authorized User
 
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yikes! I spoke too soon Michael, it didn't work. If I use the code ->

                    <xsl:for-each select="fact">
                      <xsl:sort select="slot[name='rank']/@value" data-type="number"/>
                      <td align="center">
                        <xsl:value-of select="value"/>
                      </td>
                    </xsl:for-each>

Nothing gets returned back. Then I tried to vary it a little, and I used ->

              <xsl:for-each select="fact">
                <xsl:if test="name = 'MAIN::SNPRank'">
                  <tr width="80%" align="center">
                    <xsl:for-each select="slot">
                      <xsl:sort select="slot[name='rank']/@value" data-type="number"/>
                      <td align="center">
                        <xsl:value-of select="value"/>
                      </td>
                    </xsl:for-each>
                  </tr>
                </xsl:if>
              </xsl:for-each>

With this code, I at first thought it was working, but then I realized that it was just returning the rows in the order that you entered the data. So if I use this XML ->


<fact>
  <name>MAIN::SNPRank</name>
  <slot>
    <name>id</name>
    <value type='STRING'>rs4525</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::SNPRank</name>
  <slot>
    <name>id</name>
    <value type='STRING'>rs405509</value>
    </slot>
  <slot>
    <name>rank</name>
    <value type='STRING'>0.20</value>
  </slot>
  <slot>
    <name>category</name>
    <value type='STRING'>locus-region</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>

I get back this result ->

rs4525 0.60 nonsynonymous
rs405509 0.20 locus-region
rs13266634 0.60 nonsynonymous

When of course, I want rs13266634 listed above rs405509.
I also tried adding on order="ascending" as well as order="descending" to the sort line, still it's not looking like it's sorting.

Any other possible thoughts? I'd really be very appreciative if someone could help me figure this out.
 
Old April 1st, 2007, 11:15 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

slot[name='rank']/@value

means "select the 'value' attribute of the 'slot' that has a child called 'name' whose value is 'rank'"

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 1st, 2007, 11:45 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If I use the code ->

                    <xsl:for-each select="fact">
                      <xsl:sort select="slot[name='rank']/@value" data-type="number"/>
                      <td align="center">
                        <xsl:value-of select="value"/>
                      </td>
                    </xsl:for-each>

That's may be because you've got the context node wrong. select="fact" will select nothing unless your context node is the parent element of the fact elements. And I got the sort wrong: value is an element not an attribute, so it should be "value" rather than "@value".

<xsl:for-each select="slot">
                      <xsl:sort select="slot[name='rank']/@value" data-type="number"/>

This certainly suggests you haven't mastered the idea of the context node, because a "slot" element doesnt' have a child called "slot".

But what are you trying to do: sort the facts, or sort the slots within each fact? This isn't "varying it a little", it's solving a completely different problem.




Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 1st, 2007, 03:51 PM
Authorized User
 
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, I'm still a beginner and I didn't understand the "slot[name='rank']/@value" code, so I used the wrong context node.

I'm not 100% sure if I'm sorting the facts or slots within the fact. I know I'm trying to get the output to look like this ->

rs4525 0.60 nonsynonymous
rs13266634 0.60 nonsynonymous
rs405509 0.20 locus-region

I'm guessing that would be sorting the slots, but each slot still has to remain connected to the facts, so in a way, I guess you could also call it sorting the facts.

I haven't been able to find any code examples that do this in the w3schools.com website. And unfortunately, I don't know anyone who's an XSLT expert.


When I used this code (which was your original suggestion, except using "value" instead of "@value") ->

         <xsl:template match="rules">
              <xsl:for-each select="fact">
                <tr width="80%" align="center"/>
                <xsl:sort select="slot[name='rank']/value" data-type="number"/>
                <td align="center">
                  <xsl:value-of select="value"/>
                </td>
              </xsl:for-each>
            </xsl:template>

I got this error message ->
Error during XSLT transformation: XSLT transformation failed.

I should probably clarify that the XML I'm working with actually includes a top tag element called "rules". So, it looks like ->

<rules>

<fact>
  <name>MAIN::SNPRank</name>
  <slot>
    <name>id</name>
    <value type='STRING'>rs4525</value>
  </slot>
  <slot>
    <name>rank</name>
    <value type='STRING'>0.60</value>
  </slot>
  <slot>
    <name>category</name>
    <value type='STRING'>nonsynonymous</value>
  </slot>
</fact>

MORE FACTS....

</rules>


Could that be why it's having issues? Again, thanks for your patience in this matter.
As before, any help from anyone would be much appreciated.
 
Old April 1st, 2007, 04:17 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your output is trying to sort the facts, not the slots (that is, the rows in your table, not the cells within each row). So you need the xsl:sort at the select="fact" level.

I got this error message ->
Error during XSLT transformation: XSLT transformation failed.

This suggests some configuration problem in your setup that is causing the true error message not to be displayed.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 1st, 2007, 07:25 PM
Authorized User
 
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I got rid of the error message, but it still doesn't work, nothing gets returned. This is the code again ->

        <xsl:template match="rules">
          <tr bgcolor="#aaccdd">
            <th><h2>SNP rs number</h2></th>
            <th><h2>Rank Score</h2></th>
            <th><h2>Ranking Determination</h2></th>
          </tr>
          <xsl:for-each select="fact">
                 <xsl:sort select="slot[name='rank']/value" data-type="number"/>
                    <td align="center">
                       <xsl:value-of select="value"/>
                    </td>
          </xsl:for-each>
        </xsl:template>


Oh, well... of course, if you have any more insights I'd be most thankful, but if not, thanks for your suggestions anyway.
 
Old April 2nd, 2007, 02:49 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please supply a complete XML document and a complete stylesheet, so we can see what's going on.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 2nd, 2007, 03:32 AM
Authorized User
 
Join Date: Mar 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh, thanks so much for looking at them! I should warn you that they are really long, though (I had to delete 80% of the XML file because there are 1000 facts; we can't save documents to this forum, and anything too long can't be posted on the forum), and they're part of a bunch of other files and stylesheets so they will sometimes reference other files. The ranking scores are located at the bottom on the XML file, they are the ones with the fact name MAIN::SNPRank. Again, I really am appreciative about this. I'm a beginner in programming and there's no one else in my department that uses XSLT, or else I'd usually ask them.

Again, what I'm trying to get for the output is just the SNPRank facts, sorted by it's score. So the final output should look like ->

rs4525 0.60 nonsynonymous
rs13266634 0.60 nonsynonymous
rs405509 0.20 locus-region


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


<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="/biomediator/projects/SNP/web/rulessearch.xsl"?>
<rules>
<fact>
  <name>MAIN::SNP</name>
  <slot>
    <name>SourceID</name>
    <value type='STRING'>rs405509</value>

  </slot>

  <slot>
    <name>Source</name>
    <value type='STRING'></value>

  </slot>
  <slot>
    <name>DBName</name>
    <value type='SYMBOL'>dbSNP</value>


  </slot>
  <slot>
    <name>Chromosome</name>
    <value type='STRING'>19</value>

  </slot>
  <slot>
    <name>ObservedAlleles</name>

    <value type='STRING'>A/C</value>

  </slot>
  <slot>
    <name>ChromosomeStart</name>
    <value type='STRING'>50100675</value>

  </slot>
  <slot>

    <name>PredictedFunctionalRole</name>
    <value type='STRING'>locus-region</value>

  </slot>
  <slot>
    <name>ValidationMethod</name>
    <value type='STRING'>by-2hit-2allele,by-cluster,by-frequency</value>

  </slot>

<fact>
  <name>MAIN::LinkageDisequilibriumPopulation</name>
  <slot>
    <name>SourceID</name>
    <value type='STRING'>~127~</value>

  </slot>
  <slot>

    <name>Source</name>
    <value type='STRING'></value>

  </slot>
  <slot>
    <name>DBName</name>
    <value type='SYMBOL'>GVS</value>

  </slot>

  <slot>
    <name>PopId</name>
    <value type='STRING'>595</value>

  </slot>
  <slot>
    <name>SNP1</name>
    <value type='STRING'>rs4525</value>


  </slot>
  <slot>
    <name>r2Score</name>
    <value type='STRING'>0.28</value>

  </slot>
  <slot>
    <name>SNP2</name>

    <value type='STRING'>rs1988608</value>

  </slot>
</fact>

<fact>
  <name>MAIN::LinkageDisequilibriumPartOfPopulatio n</name>
  <slot>
    <name>HeadDB</name>
    <value type='SYMBOL'>GVS</value>


  </slot>
  <slot>
    <name>HeadID</name>
    <value type='STRING'>~127~</value>

  </slot>
  <slot>
    <name>TailDB</name>

    <value type='SYMBOL'>GVS</value>

  </slot>
  <slot>
    <name>TailID</name>
    <value type='STRING'>rs4525</value>

  </slot>
</fact>

<fact>
  <name>MAIN::LinkageDisequilibriumEvidenceForSNP</name>
  <slot>
    <name>HeadDB</name>
    <value type='SYMBOL'>GVS</value>

  </slot>
  <slot>
    <name>HeadID</name>

    <value type='STRING'>~127~</value>

  </slot>
  <slot>
    <name>TailDB</name>
    <value type='SYMBOL'>dbSNP</value>

  </slot>
  <slot>

    <name>TailID</name>
    <value type='STRING'>rs4525</value>

  </slot>
</fact>

<fact>
  <name>MAIN::LinkageDisequilibriumPartOfPopulatio n</name>
  <slot>
    <name>HeadDB</name>

    <value type='SYMBOL'>GVS</value>

  </slot>
  <slot>
    <name>HeadID</name>
    <value type='STRING'>~156~</value>

  </slot>
  <slot>

    <name>TailDB</name>
    <value type='SYMBOL'>GVS</value>

  </slot>
  <slot>
    <name>TailID</name>
    <value type='STRING'>rs4525</value>

  </slot>

</fact>

<fact>
  <name>MAIN::HumanGeneMutation</name>
  <slot>
    <name>SourceID</name>
    <value type='STRING'>APOE</value>

  </slot>
  <slot>

    <name>Source</name>
    <value type='STRING'></value>

  </slot>
  <slot>
    <name>DBName</name>
    <value type='SYMBOL'>HGMD</value>

  </slot>

  <slot>
    <name>NumRepeatVariations</name>
    <value type='STRING'>0</value>

  </slot>
  <slot>
    <name>TotalNumMutations</name>
    <value type='STRING'>41</value>


  </slot>
  <slot>
    <name>NumComplexRearrangements</name>
    <value type='STRING'>0</value>

  </slot>
  <slot>
    <name>NumSmallDeletions</name>

    <value type='STRING'>5</value>

  </slot>
  <slot>
    <name>NumGrossInsertions</name>
    <value type='STRING'>2</value>

  </slot>
  <slot>

    <name>NumMissenseNonsense</name>
    <value type='STRING'>28</value>

  </slot>
  <slot>
    <name>GeneName</name>
    <value type='STRING'>Apolipoprotein E</value>

  </slot>

  <slot>
    <name>NumRegulatory</name>
    <value type='STRING'>3</value>

  </slot>
  <slot>
    <name>NumSmallInsertions</name>
    <value type='STRING'>0</value>


  </slot>
  <slot>
    <name>NumSmallIndels</name>
    <value type='STRING'>1</value>

  </slot>
  <slot>
    <name>NumSplicing</name>

    <value type='STRING'>1</value>

  </slot>
  <slot>
    <name>NumGrossDeletions</name>
    <value type='STRING'>1</value>

  </slot>
  <slot>

    <name>DiseasePhenotype</name>
    <value type='STRING'>Hyperlipoproteinaemia III</value>

  </slot>
</fact>

<fact>
  <name>MAIN::HumanGeneMutation</name>
  <slot>
    <name>SourceID</name>

    <value type='STRING'>F5</value>

  </slot>
  <slot>
    <name>Source</name>
    <value type='STRING'></value>

  </slot>
  <slot>
    <name>DBName</name>

    <value type='SYMBOL'>HGMD</value>

  </slot>
  <slot>
    <name>NumRepeatVariations</name>
    <value type='STRING'>0</value>

  </slot>
  <slot>

    <name>TotalNumMutations</name>
    <value type='STRING'>44</value>

  </slot>
  <slot>
    <name>NumComplexRearrangements</name>
    <value type='STRING'>1</value>

  </slot>

  <slot>
    <name>NumSmallDeletions</name>
    <value type='STRING'>10</value>

  </slot>
  <slot>
    <name>NumGrossInsertions</name>
    <value type='STRING'>0</value>


  </slot>
  <slot>
    <name>NumMissenseNonsense</name>
    <value type='STRING'>25</value>

  </slot>
  <slot>
    <name>GeneName</name>

    <value type='STRING'>Factor V</value>

  </slot>
  <slot>
    <name>NumRegulatory</name>
    <value type='STRING'>0</value>

  </slot>
  <slot>

    <name>NumSmallInsertions</name>
    <value type='STRING'>5</value>

  </slot>
  <slot>
    <name>NumSmallIndels</name>
    <value type='STRING'>0</value>

  </slot>

  <slot>
    <name>NumSplicing</name>
    <value type='STRING'>3</value>

  </slot>
  <slot>
    <name>NumGrossDeletions</name>
    <value type='STRING'>0</value>


  </slot>
  <slot>
    <name>DiseasePhenotype</name>
    <value type='STRING'>Thrombosis, increased risk</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'>rs4525</value>


  </slot>
</fact>

<fact>
  <name>MAIN::SNPRank</name>
  <slot>
    <name>id</name>
    <value type='STRING'>rs4525</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'>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'>locus-region</value>

  </slot>
  <slot>
    <name>rsnum</name>
    <value type='STRING'>rs405509</value>

  </slot>

</fact>

<fact>
  <name>MAIN::SNPRank</name>
  <slot>
    <name>id</name>
    <value type='STRING'>rs405509</value>

  </slot>
  <slot>

    <name>rank</name>
    <value type='STRING'>0.20</value>

  </slot>
  <slot>
    <name>category</name>
    <value type='STRING'>locus-region</value>

  </slot>

</fact>

</rules>

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

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">

    <html>
      <head>

        <meta content="text/xsl; charset=ISO-8859-1" http-equiv="content-type">
          <link rel="stylesheet" type="text/css" href="stylesheet.css"/>

          <title>SNPit Rules Query Results</title>
          <meta content="Servlet Interface to BioMediator Query Engine" name="description"> </meta>
        </meta>
      </head>

      <body>

        <div id="main">

          <div id="hlinks">
            <p align="left">SNPit Rules Search Results</p>
          </div>

          <div id="top">
            <table>
              <tr>
                  <p id="links">
                    |
                    <a href="index.html">
                      Home
                    </a>
                    |
                    <a href="mainsearch.html">
                      Main Search
                    </a>
                    |
                    <a href="rulessearch.html">
                    Rank SNPs
                    </a>
                    |
                    <a href="instructions.html">
                      About
                    </a>
                    |
                  </p>
              </tr>
            </table>
          </div>


          <div id="htitle">
            <img src="images/snp-header.jpg" alt="" style="width:100%;"/>
          </div>


          <br/>


          <div class="biomediator_table">

            <table border="1" padding="1">
                  <tr align="center">
                    <h1>Rules Search Results</h1>
                  </tr>
                  <br></br>
                      <xsl:apply-templates/>
              </table>

          </div>
          <br/>
        </div>

      </body>
    </html>

      </xsl:template>

        <xsl:template match="rules">
          <tr bgcolor="#aaccdd">
            <th><h2>SNP rs number</h2></th>
            <th><h2>Rank Score</h2></th>
            <th><h2>Ranking Determination</h2></th>
          </tr>
          <xsl:for-each select="fact">
                 <xsl:sort select="slot[name='rank']/value" data-type="number"/>
                    <td align="center">
                       <xsl:value-of select="value"/>
                    </td>
          </xsl:for-each>
        </xsl:template>

</xsl:stylesheet>





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.