Saturday, February 19, 2011

Output result of xsl:value-of in an xml attribute

I have an XML input file and I'm trying to output the result of a call like:

<xsl:value-of select="Some/Value"/>

into an attribute.

<Output Attribute="Value should be put here"/>

My problem is since I'm outputing XML the xsl processor won't allow me to write:

<Output Attribute="<xsl:value-of select="Some/Value"/>">

How do you accomplish this?

From stackoverflow
  • You need to use an xsl:attribute element:

    <Output>
      <xsl:attribute name="Attribute">
        <xsl:value-of select="Some/Value"/>
      </xsl:attribute>
    </Output>
    
  • The easiest way is to use attribute value templates, like this:

    <Output Attribute="{Some/Value}"/>
    

0 comments:

Post a Comment