I've been having a very similar problem but I
didn't have the luxury of knowing all attributes statically in advance. I solved it in a surprisingly simple way.
The problematic code:
Code:
<xsl:element name="article">
<xsl:attribute name="xml:id"><xsl:apply-templates select="uut:UUTDescription/@uuid" mode="normalizeUuid"/></xsl:attribute>
<xsl:attribute name="xsi:schemaLocation">http://docbook.org/ns/docbook docbook.xsd</xsl:attribute>
<xsl:attribute name="xmlns:xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:attribute>
<xsl:attribute name="version">5.0</xsl:attribute>
<xsl:attribute name="xmlns:xlink">http://www.w3.org/1999/xlink</xsl:attribute>
[...]
</xsl:element>
What I was going for (desired result of transformation):
Code:
<article xml:id="VARIABLE"
xsi:schemaLocation="http://docbook.org/ns/docbook docbook.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="5.0"
xmlns:xlink="http://www.w3.org/1999/xlink">
[...]
</article>
Error I got upon compiling the XSL stylesheet:
Code:
Prefix 'xmlns' is not defined.
What I did:
I shoved the <xsl:apply-templates select="uut:UUTDescription/@uuid" mode="normalizeUuid"/> into a variable such as:
Code:
<xsl:variable name="uuid"><xsl:apply-templates select="tc:TestConfiguration/@uuid" mode="normalizeUuid"/></xsl:variable>
and referred to it at the place that says "VARIABLE" in the above code.
The key thing here is that you need to
enclose this reference in curly brackets such as
Code:
<article xml:id="{$uuid}"
xsi:schemaLocation="http://docbook.org/ns/docbook docbook.xsd"
[...]
to force the evaluation of the variable. Without the curly brackets you'd just end up with a string that says "$uuid".
Hope this helps someone in the future.