dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: problem with population xslt dropdown with xml

  1. #1
    Join Date
    Apr 2015
    Posts
    2

    problem with population xslt dropdown with xml

    hi
    my xml is as follow

    Code:
    <userDetails>
      <user>
       <cities>
         <cityname value="0"> --Select One--</cityname>
         <cityname value="0"> City 1</cityname>
         <cityname value="0"> City 2</cityname>
         <cityname value="0"> City 3</cityname>
       </cities>
     </user>
    <userDetails>
    the xslt for the above is:

    Code:
    <SELECT NAME="userDetails/user/cities">
        <xsl:for-each select="cities">
            <OPTION VALUE="{cityname}">
                <xsl:value-of select="cityname"/>
            </OPTION>
        </xsl:for-each>
    </SELECT>

    on page in the dropdown only the default "--Select One--" is being displayed, rest of the data doesn't come up

  2. #2
    Join Date
    Oct 2013
    Posts
    885
    This displays correctly in IE11. Apply changes as necessary to your code.

    XML:
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="city.xsl"?>
    <userDetails>
      <user>
       <cities>
         <cityname>--Select One--</cityname>
         <cityname>City 1</cityname>
         <cityname>City 2</cityname>
         <cityname>City 3</cityname>
       </cities>
     </user>
    </userDetails>
    XSL (arbitrarily named city.xsl):
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
      <html>
      <head>
       <title>City</title>
      </head>
      <body>
      <form>
      <select name="city">
        <xsl:for-each select="userDetails/user/cities/cityname">
            <option value="{.}">
                <xsl:value-of select="."/>
            </option>
        </xsl:for-each>
      </select>
      </form>
      </body>
      </html>
    </xsl:template>
    </xsl:stylesheet>
    Last edited by Kevin2; 04-16-2015 at 01:37 PM.

  3. #3
    Join Date
    Oct 2013
    Posts
    885
    Alternatively:

    XML:
    Code:
    <userDetails>
      <user>
       <cities>
         <cityname value="">--Select One--</cityname>
         <cityname value="City 1">City 1</cityname>
         <cityname value="City 2">City 2</cityname>
         <cityname value="City 3">City 3</cityname>
       </cities>
     </user>
    </userDetails>
    XSL:
    Code:
      <select name="city">
        <xsl:for-each select="userDetails/user/cities/cityname">
            <option value="{./@value}">
                <xsl:value-of select="."/>
            </option>
        </xsl:for-each>
      </select>
    Gives a bit better form behavior. "Select One" submits a blank.

  4. #4
    Join Date
    Apr 2015
    Posts
    2
    works like a charm !!....thanks a lot

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles