0

I would like to create a template with a param, and using this param create an element with that name.

How can this be done?

This is a non-working example, but gives an idea of what I want to do.

<xsl:call-template name="parseOneValue">
   <xsl:with-param name="name" select="'addr'" />
</xsl:call-template>

<xsl:template name="parseOneValue">
   <xsl:param name="name"/>
   <xsl:element name="$name">
     <xsl:attribute name="at">local
     </xsl:attribute>
   </xsl:element>
</xsl:template>

1 Answer 1

3

When assigning XPath expressions to attributes within an XML element you have to enclose the XPath expression with curly brackets to indicate to the XSLT processor that the value has to be dynamically calculated.

So the correct template would be:

<xsl:template name="parseOneValue">
   <xsl:param name="name"/>
   <xsl:element name="{$name}">
     <xsl:attribute name="at">local
     </xsl:attribute>
   </xsl:element>
</xsl:template>
Sign up to request clarification or add additional context in comments.

2 Comments

For reference this is called an "attribute value template" in the specification.
Thanks.. I don't know. I've done like that before but the parser complained. Now I've tried again and it works ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.