You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Robinson Simon <Si...@newton.co.uk> on 2003/03/21 15:06:06 UTC
Problem when comparing parameters against a Text node string value
I am trying to input a parameter into a stylesheet and then return the text values of the student elements Firstname and LastName. This is a simple version of the XML/XSL I am having a problem with.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE LectureList SYSTEM "classList_LectureList.dtd">
<!-- Created by sro on 21 March 2003, 09:56 -->
<LectureList>
<ClassId>
<ClassName>French</ClassName>
<StudentName>
<FirstName>Simon</FirstName>
<LastName>Robinson</LastName>
</StudentName>
</ClassId>
<ClassId>
<ClassName>German</ClassName>
<StudentName>
<FirstName>John</FirstName>
<LastName>Snow</LastName>
</StudentName>
</ClassId>
</LectureList>
Here is the XSL. What is the correct way to select a text node and then to run tests on the string values and compare against parameter values. If I type the value John into the xsl:if test, my XSL works ok, but when I use $studentName I get no output. Please help.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html" indent="yes"/>
<xsl:param name="studentName" select="'Simon'"/>
<xsl:template match="* | /"/>
<xsl:template match="/">
<xsl:apply-templates select="LectureList"/>
</xsl:template>
<xsl:template match="LectureList">
Students Taking :
<br/>
<br/>
<xsl:apply-templates select="ClassId"/>
</xsl:template>
<!-- /LectureList/ClassId/StudentName/FirstName='Simon' -->
<xsl:template match="ClassId">
<xsl:apply-templates select="StudentName"/>
</xsl:template>
<xsl:template match="StudentName[child::FirstName='Simon']">
<xsl:if test="text()=string($studentName)">
<xsl:text>This bit works ok</xsl:text>
</xsl:if>
<xsl:value-of select="child::FirstName"/>
<xsl:value-of select="child::LastName"/>
</xsl:template>
</xsl:stylesheet>
Regards
Simon
Re: Problem when comparing parameters against a Text node string value
Posted by kl...@attbi.com.
If your example is correct, it won't work
because you are comparing a first name to both
a first and last name.
Kevin