Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
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 Search this Thread Display Modes
  #1 (permalink)  
Old April 11th, 2006, 12:38 PM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sorting a xsl:if test="position()"

Hi All,

I am wondering if someone can help.
I am trying to sort an XSL transformation where the output is from xsl:if statements....
I need to sort the output in ascending order of the following xsl:if
<xsl:if test="position()=9">

Charmaigne
================================================== ==
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:qq="urn:schemas-microsoft-com:office:spreadsheet" version="1.0">
<xsl:template match="/">
    <HTML>
    <TABLE>
   <xsl:for-each select="qq:Workbook/qq:Worksheet/qq:Table/qq:Row">
   <TR>
    <xsl:for-each select="qq:Cell">
            <xsl:if test="position()=1">
                <TD>
                    <xsl:value-of select="qq:Data"/>
                </TD>
            </xsl:if>
            <xsl:if test="position()=9">
                <TD>
                    <xsl:value-of select="qq:Data"/>
                </TD>
            </xsl:if>
        <xsl:if test="position()=7">
            <TD>
                <xsl:value-of select="qq:Data"/>
            </TD>
        </xsl:if>
        <xsl:if test="position()=11">
            <TD>
                <xsl:value-of select="qq:Data"/>
            </TD>
        </xsl:if>
        <xsl:if test="position()=4">
            <TD>
                <xsl:value-of select="qq:Data"/>
            </TD>
        </xsl:if>
    </xsl:for-each>
       </TR>
   </xsl:for-each>

    </TABLE>
    </HTML>
</xsl:template>
</xsl:stylesheet>

Reply With Quote
  #2 (permalink)  
Old April 11th, 2006, 05:39 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your inner for-each seems a rather convoluted way of writing

<xsl:for-each select="qq:Cell[position() = (1,4,7,9,11)]">
                <TD>
                    <xsl:value-of select="qq:Data"/>
                </TD>
</xsl:for-each>

That's 2.0 syntax: in 1.0 you have to write the predicate as

position() = 1 or position() = 4 or ...

You don't make it clear, but I suspect you want to sort the rows (the outer for-each) not the columns. So the outer for-each becomes

<xsl:for-each select="qq:Workbook/qq:Worksheet/qq:Table/qq:Row">
  <xsl:sort select="qq:Cell[9]/qq:Data"/>

You need to be aware that there is no guarantee when you export an Excel spreadsheet as XML that the 9th Cell in a Row represents the contents of column 9 in the spreadsheet. Empty cells and cells spanning multiple columns can affect the count. But perhaps it works for your particular spreadsheet.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old April 12th, 2006, 04:42 AM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael,

Thankyou so much, the sort worked fantastically...
The first part to the solution concating all the position() in one did not, I think this may be as you sugessted that I am using and old version on XSL...

Charmaigne

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
XSL 1.0 : How to find 8th position from string elayaraja.s XSLT 1 July 29th, 2008 04:26 AM
XML, XSL:FO- saving position() mikevn123 XSLT 0 August 8th, 2006 02:51 PM
combining a form input name with xsl position() ? joeprice XSLT 1 February 23rd, 2006 09:54 AM
XSL Test tclancy XSLT 2 February 3rd, 2006 02:49 PM
Using xsl:if test attributes rdavisiii XSLT 4 November 9th, 2004 12:24 AM



All times are GMT -4. The time now is 12:22 AM.


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