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

Thread: What is wrong with this simpe xslt ?

  1. #1
    Join Date
    Sep 2005
    Posts
    45

    What is wrong with this simpe xslt ?

    Hi,

    I have a simple xslt problem from a tutorial and I am getting the
    wrong result and makes no sense. This I'm sure is trivial but I just
    need to catch the error... By the way I am using Oxygen xml editor
    that does transforms to and I have suceesfully run samples from this
    tutorial... http://www.cafeconleche.org/books/xian3/examples/08/

    My XML file is:
    HTML Code:
    <?xml version="1.0" ?>
    <sample>
            <option value="Afghanistan" >Afghanistan</option>
            <option value="Albania" >Albania</option>
            <option value="Algeria" >Algeria</option>
            <option value="Andorra" >Andorra</option>
            <option value="Antigua and Barbuda" >Antigua and Barbuda</
    option>
    </sample>
    My XSL file contains

    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
     <xsl:template match="sample">
        <xsl:value-of select="option"/>
     </xsl:template>
    </xsl:stylesheet>
    Yet in my result I get only:

    Afghanistan

    My intended result is all 4 listed countries.

    TIA

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    xsl:value-of grabs the text associated with the first elemet that matches the select. You want xsl:apply-templates.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Sep 2005
    Posts
    45
    Thanks that helped. Got it working so:

    HTML Code:
    <xsl:stylesheet version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     
     <xsl:template match="sample">
      <xsl:text> Top header</xsl:text>
      
      <xsl:apply-templates></xsl:apply-templates>
     </xsl:template>
     
     <xsl:template match="option">
      <xsl:text> Prefix text: </xsl:text><xsl:value-of select="."/>  </xsl:template>
     
    </xsl:stylesheet>

Thread Information

Users Browsing this Thread

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

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