[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Article Paging With Conditions

Subject: RE: Article Paging With Conditions
From: cknell@xxxxxxxxxx
Date: Thu, 16 Jan 2003 13:15:15 -0500
asp paging with condition
> kubs.benjamin@xxxxxxxxxxxxxxxxxxxx

> The problem is that I do not want some articles to be accessible to > previous and next because they are small articles or helper
> articles. A snippet of the xml code is below:
> 
> <article id="1" display="contents" />
> <article id="2" display="contents" />
> <article id="3" display="contents" />
> <article id="4" display="none" />
> <article id="5" display="none" />
> <article id="6" display="contents" />

I think you will simplify matters if you replace the <xsl:if> with a template which only matches the nodes you want. In your code you show this opening tag:

  <xsl:if test="../article[@id = $artID + 1]">

Try replacing this section with a template which matches what you're looking for:

<xsl:template match="article[@display='contents' and position() != last()]">
  <!-- code goes here -->
<xsl:template>

Now you are only processing the nodes whose display attribute has the value of "contents", and ignoring any others, including those whose "display" attribute is set to "none". By excluding the last "article" element, you won't be outputting an invalid link on the final page. By definition, the last element (one for which the position() function returns the same value as the last() function) has no following siblings. For this one, the value of $next-article-id (see below) is the empty string.

Inside this template you want to use the value of the "id" attribute of the first node along the context node's sibling axis which also has it's "display" attribute set to "contents". Set up the variable this way:

<xsl:template match="article[@display='contents']">
  <xsl:variable name="next-article-id">
    <xsl:value-of select="following-sibling::article[@display = 'contents']/@id[1]" />
  </xsl:variable>
<xsl:template>

Now you can use $next-article-id directly instead of adding 1 to it as you had been doing with $artID.

Here is the complete replacement for your template. I have replaced the variable $issueID with a constant to simplify (and because your fragment gives no clue as to what it might be based on).

<xsl:template match="article[@display='contents' and position() != last()]">
  <xsl:variable name="next-article-id">
    <xsl:value-of select="following-sibling::article[@display = 'contents']/@id[1]" />
  </xsl:variable>
    <span style="width: 43%; float: right; text-align:right;">
      <a class="BottomNav" href="/cattails/cat/default.asp?artID={$next-article-id}">
        <img src="/cattails/images/next.gif" align="right" border="0" vspace="12" hspace="5" />
        <strong>Next Article</strong><br />
        <xsl:value-of select="following-sibling::article[@display = 'contents']/title[1]" />
      </a>
    </span>
</xsl:template>

-- 
Charles Knell
cknell@xxxxxxxxxx - email



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.