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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:59:37+00:00 2026-05-11T18:59:37+00:00

My requirement is -using XSLT- to show a dropdown list with the US states

  • 0

My requirement is -using XSLT- to show a dropdown list with the US states and print ‘selected’ on one specific that is declared in the XML which will use my style sheet.

I was thinking on declare an array with the states and iterate it but I don’t know how to do it.

NOTE: More ideas are welcome 😉

  • 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-11T18:59:37+00:00Added an answer on May 11, 2026 at 6:59 pm

    One way to do this is to embed the state data into the stylesheet itself, and access the stylesheet document using document(''), as follows:

    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:my="whatever"
      exclude-result-prefixes="my">
    
      <xsl:output indent="yes"/>
    
      <!-- The value of the state you want to select, supplied in the input XML -->
      <xsl:variable name="selected-state" select="/xpath/to/state/value"/>
    
      <!-- You have to use a namespace, or the XSLT processor will complain -->
      <my:states>
        <option>Alabama</option>
        <option>Alaska</option>
        <!-- ... -->
        <option>Wisconsin</option>
        <option>Wyoming</option>
      </my:states>
    
      <xsl:template match="/">
        <!-- rest of HTML -->
        <select name="state">
          <!-- Access the embedded document as an internal "config" file -->
          <xsl:apply-templates select="document('')/*/my:states/option"/>
        </select>
        <!-- rest of HTML -->
      </xsl:template>
    
              <!-- Copy each option -->
              <xsl:template match="option">
                <xsl:copy>
                  <!-- Add selected="selected" if this is the one -->
                  <xsl:if test=". = $selected-state">
                    <xsl:attribute name="selected">selected</xsl:attribute>
                  </xsl:if>
                  <xsl:value-of select="."/>
                </xsl:copy>
              </xsl:template>
    
    </xsl:stylesheet>
    

    Let me know if you have any questions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am using customDialog which i was customized to show list.my Requirement is Where ever
I'm using PowerShell v1.0 (It is a requirement that I cannot use 2.0) and
Requirement: I need to run multiple animations one by one. I'm using onAnimationEnd() to
I have a requirement where i have a Video that is played using MPMediaPlayerController
I am creating HTML o/p using xsl. one of the requirement is to display
I have a requirement such that I need to add two integers using built
I have this kinda interesting requirement. Typically you use XSLT to transform an XML
I am using XSLT and XML. I have got below XML. <documentCountryInformation> <countryCode>US</countryCode> <countryName>United
My requirement is that, using waitfor condition, ant should periodically check if string Build
I have got a requirement to bind a dropdownlist using db values.I gave that

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.