Here is the basic XSL. I am trying to pull out the element q_DECISION_NUMBER and use it to create both a data element as well an ID attribute. But the data element contains whitespace, so that whitespace is also being picked up and producing: id=”23-7/16 “
I tried to use normalize-space() and translate() but neither works in this case.
Anyone have a suggestion?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Untitled Document</title>
</head>
<body>
<xsl:apply-templates select="Root"/>
</body>
</html>
</xsl:template>
<xsl:template match="q_DECISION_NUMBER">
<h2 class="q_DECISION_NUMBER"><xsl:attribute name="id">d<xsl:apply-templates/>
</xsl:attribute><xsl:apply-templates/></h2>
</xsl:template>
</xsl:stylesheet>
Here is some sample xml with typical data, not the entire XML source:
<Root><DECISION><q_DECISION_NUMBER>1-1/1 </q_DECISION_NUMBER></DECISION>
<DECISION><q_DECISION_NUMBER>1-1/2 </q_DECISION_NUMBER></DECISION>
<DECISION><q_DECISION_NUMBER>1-1/3 </q_DECISION_NUMBER></DECISION>
</Root>
Note the space in the data element above. This whitespace is being picked up by the ID attribute, but if we use the ID as the hyperlink destination, it doesn’t work. If we search and remove the trailing space the ID works fine. It’s probably something simple but I can’t figure it out.
Note:
xmlns="http://www.w3.org/1999/xhtml"on<xsl:stylesheet>: puts all elements in the output in the XHTML namespacetranslate(...): attributes of type ID in XHTML are not allowed to contain/characters