Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6344189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:35:15+00:00 2026-05-24T20:35:15+00:00

I want to create a ASP.NET user control from an XML using XSLT. Currently

  • 0

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

<xsl:template match="TextField">
   <xsl:apply-templates select="Label" />
   <xsl:text><![CDATA[<asp:TextBox ID="]]></xsl:text>
   <xsl:value-of select="@id"/>
   <xsl:if test="@defaultValue">
      <xsl:text><![CDATA[" value="]]></xsl:text>
      <xsl:value-of select="@defaultValue"/>
   </xsl:if>
   <xsl:text><![CDATA[" runat="server"></asp:TextBox>]]></xsl:text>
   <xsl:copy-of select="$br"/>
</xsl:template>

It would be rally cool if I could instead do something like this:

<xsl:template match="TextField">
   <xsl:apply-templates select="Label" />

   <xsl:variable name="localTemplate" select="expression">
      <xsl:text><![CDATA[
         <asp:TextBox ID="{theID}" value="{theDefaultValue}" runat="server"></asp:TextBox>
      ]]></xsl:text>
      <xsl:copy-of select="$br"/>
   </xsl:variable>

   <!-- replace {theID} and {theDefaultValue} from the corresponding
       values of the input XML and then return the content of that
       variable
   -->
</xsl:template>

Because that seems much cleaner and more easy to maintain later on when there is the need to change the html structure.

Is there a way to achieve this and if yes, how would that look like?
I don’t need a working solution, just some hints on what to do.

Update: Here is some sample input XML:

<?xml version="1.0" encoding="utf-8" ?>
<Form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="XmlForm.xsd">

   <Validation enabled="false" enableValidationSummary="true" />
   <FieldSet>
      <TextField id="firstInput" css-class="textfield-css-class" />

      <TextField id="secondInput" defaultValue="Wrdlbmrpft">
         <Label translatable="true" >Label Text</Label>
      </TextField>
   </FieldSet>
</Form>

The output should look like this:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="DevelopmentWeb.WebUserControl1" %>
<asp:TextBox runat="server" ID="firstInput" CssClass="textfield-css-class"></asp:TextBox>
<asp:Label runat="server" AssociatedControlID="secondInput">Label Text</asp:Label>
<asp:TextBox runat="server" ID="secondInput">Wrdlbrmpft</asp:TextBox>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:35:16+00:00Added an answer on May 24, 2026 at 8:35 pm

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ASP.Net 3.5 I want to create a user control that contains the ListView and
okay...im really puzzled with this. I want to create a regular asp.net webforms website
I want to create a web service in ASP.NET that fetches data from a
I am using ASP.NET and I want to create a barcode in a pdf
I want to programmatically create a directory on the server using ASP.NET. I have
Distributing ASP.NET user controls across different projects can be really useful when you want
I'm writting an ASP.NET MVC e-commerce app using NHibernate and I want the end-user
I have an ASP.NET user control with a button, and I want to add
I'm creating a login page. I want to create ASP.NET TextBox controls that have
I want to create a zip extractor for plugins that I create for asp.net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.