Geoff,
For the first state (Alabama), "admissions/state/text()"
evaluates to something like:
Alabama<cr><space><space><cr><space><space>
Which is NOT the same as:
Alabama
You can solve this either by using normalize-space() or by
changing your <state> elements so that they don't use a
mixed content model (i.e. containing both text and other
elements). e.g.:
<state name="Alabama">
<...>
</state>
Dan.
--
Danny Yates
Technical Architect
Abbey National Treasury Services
E-mail: Danny(_dot_)Yates(_at_)ants(_dot_)co(_dot_)uk
Phone: +44 20 7612 4017
Fax: +44 20 7612 4342
-----Original Message-----
From: Geoff [mailto:ghank(_at_)lawlead(_dot_)com]
Sent: 25 September 2002 14:38
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] xsl string comparison fails why?
I am passing a parameter to an xslt template and trying to use that
parameter in an if comparison but it evaluates to false when it appears
it should be true.
The parameter is taken from an html form select box as so:
<select name='state'>
<option value='' selected='yes'></option>
<option value="Alabama">Alabama</option>
<option value="Alaska">Alaska</option>
<option value="Arizona">Arizona</option>
<option value="Arkansas">Arkansas</option>
</select>
Then the parameter is passed via php to the xslt template like this (in
case this is relevant but it probably isn't):
<?php
$xmlfile= $_POST['catID'] . '.xml';
$xslfile= $_POST['catID'] . '.xsl';
$args = array();
$params["state"] = $_POST['state'];
// create XSLT processor
$xh = xslt_create();
// call xslt processor
// Process the document
$result = xslt_process($xh, $xmlfile, $xslfile, NULL, $args,
$params);
if ($result) {
print $result;
}
xslt_free($xh);
?>
Then Given this xml:
<?xml version="1.0" encoding="UTF-8"?>
<admissions>
<state>Alabama
<statelink
href="http://www.alabar.org/page.cfm?view=3&subgroup=main">
Bar Admissions Information</statelink>
</state>
<state>Alaska
<statelink href="http://www.alaskabar.org/index.cfm?ID=5362">
Admissions</statelink>
</state>
<state>Arizona
<statelink href="http://www.supreme.state.az.us/admis/">
Admissions Unit of the Certification & Licensing
Division</statelink>
</state>
</state>
</admissions>
Then I am trying to find the value of the parameter (a state) and print
only that state to the browser> I am trying to do this like this:
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:param name="state" />
<xsl:template match="/">
<html>
<head>
<body bgcolor="#FFFFFF">
<xsl:for-each select="admissions/state/text()">
<xsl:if test=".=$state">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The if never evalutes to true even if it is testing Alabama=Alabama.
I can print the value of the parameter using <xsl:value-of
select="$state"/> just fine
Any hints/suggestions?
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
***************************************************************************
This communication (including any attachments) contains confidential
information. If you are not the intended recipient and you have received this
communication in error, you should destroy it without copying, disclosing or
otherwise using its contents. Please notify the sender immediately of the
error.
Internet communications are not necessarily secure and may be intercepted or
changed after they are sent. Abbey National Treasury Services plc does not
accept liability for any loss you may suffer as a result of interception or any
liability for such changes. If you wish to confirm the origin or content of
this communication, please contact the sender by using an alternative means of
communication.
This communication does not create or modify any contract and, unless otherwise
stated, is not intended to be contractually binding.
Abbey National Treasury Services plc. Registered Office: Abbey National House,
2 Triton Square, Regents Place, London NW1 3AN. Registered in England under
Company Registration Number: 2338548. Regulated by the Financial Services
Authority (FSA).
***************************************************************************
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list