Can I create a template within XSLT?

后端 未结 2 818
慢半拍i
慢半拍i 2021-01-27 12:25

I want to create a ASP.NET user control from an XML using XSLT. Currently I really put the result together bit by bit:


          


        
相关标签:
2条回答
  • 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>
    
    0 讨论(0)
  • 2021-01-27 12:37

    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>
    
    0 讨论(0)
提交回复
热议问题