XSLT - Adding attribute to element in separate templates?
I'm trying to add an attribute to the 'xsl:element name="div"' element
from another template, the 'xsl:template match="KTheme"' template, but I
get a XSLT error with no error information about what failed or why it
failed. Is there a way of doing this?
Basically, when the 'xsl:apply-templates/' line is executed from the
'xsl:template name="DisplayFrame"' template, it matches against the
'KTheme' elements and should add the "style" attribute to the "div"
element:
<xsl:template match="Frame">
<xsl:call-template name="DisplayFrame">
<xsl:with-param name="FrameId" select="'frameHeader'" />
</xsl:call-template>
<xsl:element name="div">
<xsl:attribute name="id">
<xsl:value-of select="$FrameId" />
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
The template below is where the "style" attribute should be added to the
"div" element:
<xsl:template match="KTheme">
<xsl:attribute name="style">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
An example XML file:
<Document>
<Frame>
<KTheme>background-color: red;</KTheme>
</Frame>
</Document>
In reality, the 'KTheme' element is dynamically created, so it must be
done as my theory suggests, by adding an attribute from another template,
but apparently it is incorrect. Can this be done? Thank you for your time.
No comments:
Post a Comment