Jump to content
kwilliams

Position() Method Problem

Recommended Posts

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):

<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:

<?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="''" /><!-- Populated from ASP.NET doc / contains "05" value -->	<xsl:param name="current_year" select="''" /><!-- Populated from ASP.NET doc / contains "2008" value -->	<xsl:template match="/">		<!-- Pulls current month using $current_month parameter -->		<xsl:variable name="current_month_id" select="events/month[@id = $current_month and @year = $current_year]/@id" />		<!-- ***Q: How can I apply the "$current_month_id" variable to the <for-each" method below??? -->		<xsl:for-each select="events/month[position() <= 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.

Share this post


Link to post
Share on other sites

have u considered not using position() but for example events/month[@id =05] | events/month[@id =06] | events/month[@id =07]

Share this post


Link to post
Share on other sites
have u considered not using position() but for example events/month[@id =05] | events/month[@id =06] | events/month[@id =07]
I've thought of that, but I wanted to set the properties for several years of months in the XML doc. So May 2008 and May 2009 would both have an id of "05".But here's a solution that was forwarded to me my someone else in-case anyone's interested:<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>In addition to that code, I also added additional code to allow for events for next year also, like this:<xsl:for-each select="events/month[(@id >= $current_month or @year = $current_year + 1)]"> <xsl:if test="position() <= 12"> <option value="{$site_domain}{$currentpath}{@id}"> <xsl:value-of select="name" /><br /> </option> </xsl:if> </xsl:for-each>...and since the events calendar will only list 12 months at a time, I don't have to worry about events overlapping. Thanks for your input.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...