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 6371519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:04:57+00:00 2026-05-25T01:04:57+00:00

I have the following XML: <DropDownList id=Dropdown> <Label text=Dropdown/> <ListItem value=Test1/> <ListItem value=Test2/> </DropDownList>

  • 0

I have the following XML:

    <DropDownList id="Dropdown">
        <Label text="Dropdown"/>
        <ListItem value="Test1"/>
        <ListItem value="Test2"/>
    </DropDownList>

    <ListBox id="Listbox1" >
        <Label text="SingleSelect"/>
        <ListItem value="Test1"/>
        <ListItem value="Test2"/>
    </ListBox>

Then I have the following XSLT for the listbox:

<xsl:template match="ListBox">
    <th>
        <xsl:apply-templates select="./Label" />
    </th>
    <td>
        <asp:ListBox runat="server" ID="{@id}">
            <Items>
                <xsl:for-each select="./ListItem">
                    <asp:ListItem Value="{@value}">
                        <xsl:attribute name="Text">
                            <!-- fill text accordingly to text attribute or same as value when not specified-->
                            <xsl:choose>
                                <xsl:when test="@text">
                                    <xsl:value-of select="@text"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="@value"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>

                        <xsl:if test="@selected">
                            <xsl:attribute name="selected">
                                <xsl:value-of select="@selected"/>
                            </xsl:attribute>
                        </xsl:if>
                    </asp:ListItem>
                </xsl:for-each>
            </Items>
        </asp:ListBox>
    </td>
    <td>
        <xsl:apply-templates select="./*[contains(name(), 'Validation')]" />
    </td>
    <xsl:copy-of select="$br"/>
</xsl:template>

Using this approach, I would have to duplicate the whole looping for the DropDownList element too.

Now, to avoid a lot of the duplication I understand I can do something like this:

<xsl:template match="ListBox">
    <th>
        <xsl:apply-templates select="./Label" />
    </th>
    <td>
        <asp:ListBox runat="server" ID="{@id}">         
            <Items>
                <xsl:apply-templates select="./ListItem" />
            </Items>
        </asp:ListBox>
    </td>
    <td>
        <xsl:apply-templates select="./*[contains(name(), 'Validation')]" />
    </td>
    <xsl:copy-of select="$br"/>
</xsl:template>


<!-- Helper template for list items -->
<xsl:template match="ListItem">
    <asp:ListItem Value="{@value}">
        <xsl:attribute name="Text">
            <!-- fill text accordingly to text attribute or same as value when not specified-->
            <xsl:choose>
                <xsl:when test="@text">
                    <xsl:value-of select="@text"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="@value"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:attribute>

        <xsl:if test="@selected">
            <xsl:attribute name="selected">
                <xsl:value-of select="@selected"/>
            </xsl:attribute>
        </xsl:if>
    </asp:ListItem>
</xsl:template>

But what I don’t like about this is the

            <Items>
                <xsl:apply-templates select="./ListItem" />
            </Items>

pattern I would have to duplicate. Is there a way to put the <Items> {loop through ListItems}</Items> part completely into a template and use <xsl:apply-templates select="??" /> to group all ListItem child nodes together and stuff them into the looping template?

  • 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-25T01:04:58+00:00Added an answer on May 25, 2026 at 1:04 am

    Why not using a named template?

    <td>
            <asp:ListBox runat="server" ID="{@id}">
             <xsl:call-template name="LoopItems"/>
            </asp:ListBox>
    </td>
    

    with named template:

    <xsl:template name="LoopItems">
      <Items>
        <xsl:apply-templates select="ListItem" />
      </Items>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following xml and I want to fetch the value of node which
I have the following XML: <InterSection criteria=Microsoft-ASP>value</Intersection> <InterSection criteria=Microsoft-MVC>value</Intersection> <InterSection criteria=HP-MVC>value</Intersection> I need to
for example i have following xml input: <Letter> <LetterProductInfo> <Paragraph> <DisplayOrder> 20 </DisplayOrder> <Text>
assuming that I have following xml: <ns5:OrderTotal> <ns5:Name>AmountPaid</ns5:Name> <ns5:Description>Payment Received</ns5:Description> <ns5:SortOrder>4</ns5:SortOrder> <ns5:Value>16.95</ns5:Value> </ns5:OrderTotal> <ns5:OrderTotal>
I have the following XML: <sample> <value1>This is one</value1> <value2>Number two</value2> <value4>Last value</value4> </sample>
I have following XML, and i wish to save its data in my SQL
I have following XML. I was able to remove all namespaces but not able
I have following xml file: <ab> <![CDATA[ <table> <tbody> <tr> <th>abcdef</th> </tr> <tr> <p>
I have following xml as a response to a service not i want to
Currently I have following XML: <Rowsets> <Rowset> <Row> <DrilldownDepth>0</DrilldownDepth> <ScheduleWeek>---</ScheduleWeek> <ABC>---</ABC> <PQR>1500</PQR> <XYZ>15000</XYZ> <Quant>285</Quant>

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.