Click to See Complete Forum and Search --> : What is wrong with this simpe xslt ?


tuka
04-16-2009, 12:14 PM
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:

<?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


<?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

Charles
04-16-2009, 01:31 PM
xsl:value-of grabs the text associated with the first elemet that matches the select. You want xsl:apply-templates.

tuka
04-16-2009, 06:41 PM
Thanks that helped. Got it working so:


<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>