Basically I'm trying to write the node name of node stored in a variable to a file. My problem is that it works when I assign the variable's value by the select attribute and not when assigning by the content. I do need to get the latter working though, since I want that content to be conditional (which is not in the example below).
Can someone help me out on this? Thanks!
My environment is a proprietary software platform for variable data publishing using something (is engine the correct word?) from Altova to handle xslt. I'm using this engine in xslt 2.0 mode.
It all happens in this named template:
<xsl:template name="setValidatedEmail">
<xsl:param name="docType"/>
<xsl:variable name="break" select="' '"/>
<xsl:variable name="contEm1" select="."/>
<xsl:variable name="contEm2">
<xsl:copy-of select="."/>
</xsl:variable>
<validatedEmail>
<xsl:result-document ...">
<xsl:value-of select="local-name-from-QName(node-name($contEm1))"/>
<xsl:value-of select="$break"/>
<xsl:value-of select="local-name-from-QName(node-name($contEm2))"/>
</xsl:result-document>
</validatedEmail>
</xsl:template>
which is called like this:
<xsl:template match="email">
<xsl:call-template name="setValidatedEmail">
<xsl:with-param name="docType">Stockbooks</xsl:with-param>
</xsl:call-template>
</xsl:template>
local-name-from-QName(node-name($contEm1))
returns the string email
(as expected), while local-name-from-QName(node-name($contEm2))
unexpectedly returns nothing.
Your code
<xsl:variable name="contEm2">
<xsl:copy-of select="."/>
</xsl:variable>
creates a variable whose value is a new document node containing a copy of the context node or item .
.
You can change that by using an as
attribute
<xsl:variable name="contEm2" as="node()">
<xsl:sequence select="."/>
</xsl:variable>
Or (without such an as
attribute) you would need to select down into the tree e.g. $contEm2/*
to select an element inside.
As for using the select
attribute but doing conditional checks, XPath 2 and later have an if (conditional-expression) then sequence1 else sequence2
expression.