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 January 25th, 2008, 12:08 PM
Registered User
 
Join Date: Jan 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select range node

Hi,
I look to select a range of node using XSL.
I want to retrieve "Operation" node from #5 to #20, once sorted

Here is my XML :

<Operations>
    <Operation attribute1='' .... />
    <Operation attribute1='' .... />
    <Operation ... />
    <Operation ... />
    <Operation ... />
<Operations>

And here is my XSL :

<xsl:template match="Operations">
    <table id="tblOperation" cellspacing="0" cellpadding="0" width="100%">
    <xsl:apply-templates select="Operation">
        <xsl:sort select="@Priority" data-type="number" order="ascending"/>
    </xsl:apply-templates>
    </table>
</xsl:template>

<xsl:template match="Operation">
    <td>
    ........
    </td>
</xsl:template>

I tried this patterns, but they aren't work (got no result or error):
<xsl:apply-templates select="Operation[. &gt; Operation[5] and . &lt; Operation[20]">
<xsl:apply-templates select="Operation[. &gt;&gt; Operation[5] and . &lt;&lt; Operation[20]">

btw, this work
<xsl:apply-templates select="Operation[5]">

Thanks for your time!:)
Christ
 
Old January 25th, 2008, 12:14 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

try something like "Operation[position() &gt; 5 and position() &lt; 20]"

/- Sam Judson : Wrox Technical Editor -/
 
Old January 25th, 2008, 12:26 PM
Registered User
 
Join Date: Jan 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Sam

Your solution works a bit.
I retrieve the rows, but it's the rows before the sort! Is it possible to sort before retrieving the row 5 to 20 ?

btw i implement your solution like that :
<xsl:template match="Operations">
    <table id="tblOperation" cellspacing="0" cellpadding="0" width="100%">
    <xsl:apply-templates select="Operation[position() &gt; 5 and position() &lt; 20]">
        <xsl:sort select="@Priority" data-type="number" order="ascending"/>
    </xsl:apply-templates>
    </table>
</xsl:template>

Thanks

 
Old January 25th, 2008, 12:41 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The logic is probably clearer with for-each:

<xsl:for-each select="Operation">
  <xsl:sort select="@Priority" data-type="number"/>
  <xsl:if test="position() > 4 and 21 > position()">
    <xsl:apply-templates select="."/>
  </xsl:if>
</xsl:for-each>

The above is XSLT 1.0, but I don't think there are major simplifications for 2.0.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 25th, 2008, 12:47 PM
Registered User
 
Join Date: Jan 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mhkay
 The logic is probably clearer with for-each:

<xsl:for-each select="Operation">
<xsl:sort select="@Priority" data-type="number"/>
<xsl:if test="position() > 4 and 21 > position()">
    <xsl:apply-templates select="."/>
</xsl:if>
</xsl:for-each>

The above is XSLT 1.0, but I don't think there are major simplifications for 2.0.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
That works fine!!:D
Thanks a lot!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Select ancestor Node bonekrusher XSLT 2 October 16th, 2006 07:07 AM
XSLT and SELECT with a specfic date range pallone XSLT 15 May 8th, 2006 12:41 PM
Help: Select every node except these nodes arcuza XSLT 8 May 25th, 2005 08:07 AM
select single node bcadmin BOOK: XSLT Programmer's Reference, 2nd Edition 1 November 10th, 2004 12:15 PM
Excel VBA: Select range of data and plot chart? xitu Excel VBA 1 December 23rd, 2003 04:21 AM





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