I want to create a ASP.NET user control from an XML using XSLT. Currently I really put the result together bit by bit:
I don't think there would be any reason to create a variable. You should be able to do something like this:
<xsl:template match="TextField">
<xsl:apply-templates select="Label" />
<asp:TextBox ID="{@id}" value="{@defaultValue}" runat="server"/>
<xsl:copy-of select="$br"/>
</xsl:template>
or this:
<xsl:template match="TextField">
<xsl:apply-templates select="Label" />
<asp:TextBox runat="server">
<xsl:if test="@id">
<xsl:attribute name="ID">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@defaultValue">
<xsl:attribute name="value">
<xsl:value-of select="@defaultValue"/>
</xsl:attribute>
</xsl:if>
</asp:TextBox>
<xsl:copy-of select="$br"/>
</xsl:template>
Define appropriate namespace for prefix asp, e.g.:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="System.Web.UI.WebControls">
In your template simply write:
<asp:TextBox ID="{@id}" runat="server">
<xsl:if test="@defaultValue">
<xsl:attribute name="value">
<xsl:value-of select="@defaultValue"/>
</xsl:attribute>
</xsl:if>
</asp:TextBox>