Problems using conditional and selecting last entry
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 11
- Joined: Sat Jan 09, 2010 8:13 pm
Problems using conditional and selecting last entry
Hi,
I have a navigation bar which is made up from the headings of chapters, but only ones that adhere to a conditional statement. In this navbar I am trying to edit it so that all links have a small boundary between each other. At the moment I am just using the '|' symbol, but I am having problems. I am using the position() function but it is not picking out the last of the chapter headings. I think the problem may be that it is looking for the last position across all of my chapter headings rather than just the ones in the conditional statement, and so doesn't actually recognise any headings as actually being the last one. Can someone have a look at my code and let me know if this is the problem or something else, and how I could actually sort it out?!
I have a navigation bar which is made up from the headings of chapters, but only ones that adhere to a conditional statement. In this navbar I am trying to edit it so that all links have a small boundary between each other. At the moment I am just using the '|' symbol, but I am having problems. I am using the position() function but it is not picking out the last of the chapter headings. I think the problem may be that it is looking for the last position across all of my chapter headings rather than just the ones in the conditional statement, and so doesn't actually recognise any headings as actually being the last one. Can someone have a look at my code and let me know if this is the problem or something else, and how I could actually sort it out?!
Code: Select all
<xsl:for-each select="//chapter">
<xsl:if test="../title='About'">
<xsl:choose>
<xsl:when test="position()=last()">
<li>
<a href="{titleabbrev}.php"><xsl:value-of select="title" /></a>
</li>
</xsl:when>
<xsl:otherwise>
<li>
<a href="{titleabbrev}.php"><xsl:value-of select="title" /></a> |
</li>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Problems using conditional and selecting last entry
Move the test as a predicate in the for select expression
Regards,
George
Code: Select all
<xsl:for-each select="//chapter[../title='About']">
<xsl:choose>
<xsl:when test="position()=last()">
<li>
<a href="{titleabbrev}.php">
<xsl:value-of select="title"/>
</a>
</li>
</xsl:when>
<xsl:otherwise>
<li>
<a href="{titleabbrev}.php"><xsl:value-of select="title"/></a> | </li>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
George
George Cristian Bina
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service