kubs(_dot_)benjamin(_at_)marshfieldclinic(_dot_)org
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[(_at_)id = $artID + 1]">
Try replacing this section with a template which matches what you're looking
for:
<xsl:template match="article[(_at_)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[(_at_)display='contents']">
<xsl:variable name="next-article-id">
<xsl:value-of select="following-sibling::article[(_at_)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[(_at_)display='contents' and position() !=
last()]">
<xsl:variable name="next-article-id">
<xsl:value-of select="following-sibling::article[(_at_)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[(_at_)display =
'contents']/title[1]" />
</a>
</span>
</xsl:template>
--
Charles Knell
cknell(_at_)onebox(_dot_)com - email
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list