'Unable to retrieve siblings using xpath axes
XML
<list>
<item attribute="type1" class="one" description=""/>
<item attribute="type2" class="two" description=""/>
<item attribute="type1" class="three" description=""/>
<item attribute="type3" class="four" description=""/>
<item attribute="type3" class="five" description=""/>
.
.
</list>
What I want to is, create a list of all the types ie (type1, type2, type3 .. and so on like this..) Type1 Type2 Type3
and generate a table corresponding to each type. eg. Type1 {all items listed here which has attribute type1}
I also want to add navigate buttons in each table that takes the user to other tables. eg. I can move from Type2 table to Type1 table if I hit previous button and Type3 table if I hit next button.
So far, I have generated the list and tables using key() and generate-id() But I am unable to add navigation links. Any leads would be helpful
Edit: I can't show the whole code, here is some portion for idea
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="types" select="/list/item/@attribute" use="."/>
<xsl:template match="/">
<head> MY WORK </head>
<body>
<xsl:apply-templates/>
</body>
</xsl:template>
<div id="main_table" class="section">
<!-- Template createlist displays all type names with links to Table -->
<xsl:call-template name="createlist">
</xsl:call-template>
</div>
<xsl:call-template name="list_all_tables"/>
<!--template that creates list-->
<xsl:template name="createlist">
<xsl:for-each select="/list/item/@attribute[generate-id()= generate-id(key('types',.)[1])]">
<h3><a href="{concat('#',generate-id(.))}"><xsl:value-of select="."/></a></h3>
</xsl:for-each>
</xsl:template>
<!--template that creates list tables one by one -->
<xsl:template name="list_all_tables">
<xsl:for-each select="/list/item/@attribute[generate-id()= generate-id(key('types',.)[1])]">
<div class="section" id="{generate-id(.)}">
<!-- 'Previous Section' and 'Next Section' buttons -->
<!--want to create a template navigate that adds links -->
<xsl:call-template name="navigate"/>
<h1><a name="{generate-id(.)}"><xsl:value-of select="."/></a></h1>
<!--another template that creates table for a particular type-->
<xsl:call-template name="create_table">
<xsl:with-param name="attributeName" select="."/>
</xsl:call-template>
</div>
</xsl:for-each>
</xsl:template>
<xsl:template name="create_table">
<xsl:param name="attributeName"/>
<xsl:variable name="item"
select="/list/items[ @attribute=$attributeName]"/>
<table class="toc">
<tbody>
<xsl:apply-templates select="$item" mode="tab"/>
</tbody>
</table>
</xsl:template>
<xsl:template match="item" mode="tab">
<tr>
<td class="first">
<a href="{concat('#',generate-id(.))}"><xsl:value-of select="@class"/></a>
</td>
<td><xsl:value-of select="@description"/></td>
</tr>
</xsl:template>
<xsl:template name="navigate">
<span class="navigate">
<a>
<xsl:if test="position()!=1">
<xsl:attribute name="href">
<xsl:value-of select="concat('#',generate-id(preceding-sibling::*[name(.) = name(current())]))"/>
</xsl:attribute>
</xsl:if>
<xsl:text>Previous Section</xsl:text>
</a>
<a>
<xsl:if test="position()!=last()">
<xsl:attribute name="href">
<xsl:value-of select="concat('#',generate-id(following-sibling::*[name(.) = name(current())]))"/>
</xsl:attribute>
</xsl:if>
<xsl:text>Next Section</xsl:text>
</a>
</span>
</xsl:stylesheet>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
