I use this template to generate a list of internal links to various sections referenced by “id='{title}’ in an xHTML-doc.
<xsl:template match="folder/folder" mode="folderlist">
<li>[<a href="#{title}"><xsl:value-of select="title" /></a>]</li>
</xsl:template>
It works but of course does not validate, because the content of ‘title’ may contain sapces and the rule says that an “id” cannot have a space.
Let’s assume the content of {title} is: ‘Title with spaces’.
What I am trying to achieve is to remove space(s) from the content of {title} to be inserted into the href= only so the result look like this:
<a href="Titlewithspaces">
and then somehow use the original content of {title} again, so the complete resulting line becomes:
<li>[<a href="#Titlewithspaces">Title with spaces</a>]</li>
Is this possible at all ? If so, can someone tell me how to achieve this?
Thanks.
A general solution (both XPath 1.0 and XPath 2.0 — respectively XSLT 1.0 and XSLT 2.0) when we want to replace any non-alhanumeric character with, lets say, underscore:
where the variable
vAlphaNumis defined to be the string that contains all letters (A-Z and a-z) and all digits (0-9).This is the so called “double-translate method”, first proposed by @Michael Kay.