I have used the following code in my XSL:
<xsl:variable name="link" select="normalize-space(concat('#',$chapter2))/>
<a href="{$link}">Next chapter</a>
It should navigate to chapter 2 position on click of the next chapter link.
Its not navigating to chapter 2 in chrome and firefox. When I hover to the link I found that in chrome and firefox after ‘#’ some extra characters gets added like #14678776e_chapter2.
How to fix this issue.
$chapter2 is position() value
Code:
<xsl:variable name=chapter2 select="position()"/>
Code for xsl:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="w3.org/1999/XSL/Transform";
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="chapter" select="position()"/>
<xsl:variable name="link" select="concat('#',$chapter)"/>
<a href="{$link}" title="{$link}">
<xsl:value-of select="$link"/>
</a>
</xsl:template>
</xsl:stylesheet>
There is no input xml for now. The above code can be run directly
Thanks,
Sam
The name “chapter2” needs to be surrounded by quotes:
Also, make sure the template that defines chapter2 is not the same that defines chapter1, or else the variable binding of chapter1 will shadow the variable binding of chapter2, since both will equal the result of the position function. This code works fine: