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 Search this Thread Display Modes
  #1 (permalink)  
Old May 20th, 2008, 11:53 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default Position() Method Problem



I would like to pull 3 event nodes (May, June, and July) that are located within a bunch of other nodes from the following XML doc, starting with node #2 (name=May 2008):
Code:
<events>
    <month id="04" year="2008">
        <name>April 2008</name>
    </month>
    <month id="05" year="2008">
        <name>May 2008</name>
    </month>
    <month id="06" year="2008">
        <name>June 2008</name>
    </month>
    <month id="07" year="2008">
        <name>July 2008</name>
    </month>
    <month id="08" year="2008">
        <name>August 2008</name>
    </month>
</events>
I'm pulling in a parameter value from an ASP.NET doc that contains the current month's month-value (05), so now I need to only display the 3 nodes after that starting node. This the the XSLT doc that I've created:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="remove">
<xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/> 
    <xsl:param name="current_month" select="''" />
    <xsl:param name="current_year" select="''" />
    <xsl:template match="/">

        <xsl:variable name="current_month_id" select="events/month[@id = $current_month and @year = $current_year]/@id" />



        <xsl:for-each select="events/month[position() &lt;= 3]">
            <xsl:value-of select="name" /><br />
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
But I'm stuck on how to only pull the 3 nodes after that original node. I know that using the position() method is probably the way to go, but I can't figure out how to do it. If anyone could point me in the right direction, it would be greatly appreciated.

KWilliams
Reply With Quote
  #2 (permalink)  
Old May 20th, 2008, 12:13 PM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 33%
Activity: 33% Activity: 33% Activity: 33%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Why do you store the id in a variable? If you want to use a variable then I would simply store the month element e.g.
Code:
<xsl:variable name="current_month" select="events/month[@id = $current_month and @year = $current_year]"/>
<xsl:for-each select="$current-month | $current_month/following-sibling::month[position() &lt; 3]">
--
  Martin Honnen
  Microsoft MVP - XML
Reply With Quote
  #3 (permalink)  
Old May 20th, 2008, 01:41 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Martin,

I tried your code, but received a "this expression must evaluate a node" error. But I received a response from someone else that worked great. Here it is in-case anyone's interested:
Code:
<xsl:for-each select="events/month[@id >= $current_month]">
  <xsl:if test="position() < 3">
    <xsl:value-of select="name" /><br />
  </xsl:if>
</xsl:for-each>
Again, thanks so much for your input!

KWilliams
Reply With Quote
  #4 (permalink)  
Old May 20th, 2008, 02:11 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...also, in order to pull nodes for the next year, I added this to the <for-each> method:
<xsl:for-each select="events/month[(@id &gt;= $current_month or @year = $current_year + 1) and position() &lt;= 3]">

It worked like a charm. Thanks again.

KWilliams
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
Problem while using position() in for-loop LeoMathew XSLT 4 March 25th, 2008 07:08 AM
Customised list - Image position problem terra CSS Cascading Style Sheets 6 September 1st, 2005 01:28 PM
Problem with a method? savoym C# 1 January 6th, 2005 09:34 AM
unspecified method problem? nerssi BOOK: Professional Jakarta Struts 0 September 12th, 2004 06:40 AM



All times are GMT -4. The time now is 01:29 PM.


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