Reputation: 1
I want to make a xsl template that automatically generates a gradient background in XAML. In order to do this, I have a parameter $control, which should be concatenated in the element name to '.Background'. Example: I have a Canvas to which I want to add a gradient background, I have to add an element "Canvas.Background". For some reason this concatenation fails, no matter how I adjust it.
<xsl:template name="get-gradient-background">
<xsl:param name="control"/>
<xsl:param name="start-color"/>
<xsl:param name="end-color"/>
<xsl:param name="offset" select="1"/>
<xsl:element name="concat($control, '.Background)">
<xsl:element name="LinearGradientBrush">
<xsl:element name="GradientStop">
<xsl:attribute name="Color"><xsl:value-of select="$start-color"/></xsl:attribute>
</xsl:element>
<xsl:element name="GradientStop">
<xsl:attribute name="Color"><xsl:value-of select="$end-color"/></xsl:attribute>
<xsl:attribute name="Offset"><xsl:value-of select="$offset"/></xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
Expected outcome (for a Canvas):
<Canvas.Background>
<LinearGradientBrush>
<GradientStop Color="#FF93C5E8" />
<GradientStop Color="#FF3B596E" Offset="1" />
</LinearGradientBrush>
</Canvas.Background>
Edit:
<xsl:template name="get-gradient-background">
<xsl:param name="control"/>
<xsl:param name="start-color"/>
<xsl:param name="end-color"/>
<xsl:param name="offset" select="1"/>
<xsl:element name="concat({$control}, '.Background)">
<xsl:element name="LinearGradientBrush">
<xsl:element name="GradientStop">
<xsl:attribute name="Color">
<xsl:value-of select="$start-color"/>
</xsl:attribute>
</xsl:element>
<xsl:element name="GradientStop">
<xsl:attribute name="Color">
<xsl:value-of select="$end-color"/>
</xsl:attribute>
<xsl:attribute name="Offset">
<xsl:value-of select="$offset"/>
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
Another thing I've tried:
<xsl:element name="{concat($control, '.Background)}">
Upvotes: 0
Views: 2149
Reputation: 3903
If you are using a variable, the element name must be wrapped in a Attribute Value Template (Curly Brackets)
<xsl:element name="{concat($control, '.Background')}">
Upvotes: 2