I have code that I expect to return the element name, but nothing is returned.
The following code is from an XSL doc that generates another XSL doc.. where $expression is a variable that dynamically created an XPath expression.
<xsl:template match="/">
...
<xslt:template match="{$expression}">
<elem key="{name()}">
<xslt:copy-of select="@*"/>
<xslt:for-each select="@*">
<xslt:sort select="name()"/>
<attribute>|<xslt:value-of select="name()"/>|</attribute>
</xslt:for-each>
</elem>
</xslt:template>
...
</xsl:template>
That code then generates the second XSL doc with this code.. notice how @key is blank.
<xsl:template match="//*[@name='Spot']">
<elem key="">
<xsl:copy-of select="@*" />
<xsl:for-each select="@*">
<xsl:sort select="name()" />
<attribute>|<xsl:value-of select="name()" />|</attribute>
</xsl:for-each>
</elem>
</xsl:template>
Besides the @key being blank, everything works as expected. My only problem is displaying the name of the element.
EDIT: To clarify what I’m actually looking for, I need the names of the elements from the results returned by <xslt:template match="{$expression}">.
Thanks! 🙂
Because your transformation is producing itself XSLT code and you want to have in the result:
you must escape the
{and}, so that the AVT is not evaluated immediately.Producing
{and}as-is is done by doubling them as specified in the XSLT spec:Therefore, replace:
with:
and as result you will get:
Note: I am surprised that this code works at all. You should be using the
<xsl:namespace-alias>XSLT instruction.