RE: [xsl] Starts-with not working with numbers

Subject: RE: [xsl] Starts-with not working with numbers
From: "Josh Canfield" <Josh.Canfield@xxxxxxxxxxxx>
Date: Tue, 9 Mar 2004 17:49:27 -0800
<xsl:for-each select="//POINT_RECORDS/POINT_REC">

There is no predicate to limit your POINT_REC elements in your for-each statement, which would explain why you are getting back everything, shouldn't it be 
<xsl:for-each select="//POINT_RECORDS/POINT_REC[starts-with(ZIP_CD, $param1)]">

Good luck,
Josh

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Grant,
Kathryn --- Sr. Technical Writer --- WGO
Sent: Tuesday, March 09, 2004 5:16 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Starts-with not working with numbers


Hello,

I have an XML file of city, state and ZIP codes, and an HTML form where the user can input a full or partial ZIP code (param1). I'm trying to use <choose> to return a list of matching ZIP codes.

The first "when" section checks to see if any ZIP_CD is an exact match for param1. It works fine.

The second "when" section is supposed to check to see if any ZIP_CD *starts with* param1. BUT I can't get it to work. Instead, it returns a list of all ZIP codes in the file. I wondered if this was because they were numbers, so I tried converting them with string(), which didn't work, and then number() (getting desperate) which also didn't work. I even tried translate(), translating the numbers to letters, but that also didn't work.

The "otherwise" section also fine--if I input a non-existent ZIP code, I get the "no matches found" message.

How can I get the second "when" to pull a list of ZIP codes that start with param1?

Thanks in advance!

Kathryn

<xsl:choose>
<xsl:when test="//POINT_RECORDS/POINT_REC/ZIP_CD=$param1">

<TABLE border="0" width="90%" style="font-size: 10pt" cellspacing="1" cellpadding="1">
<tr>
<th><b>City</b></th>
<th><b>State</b></th>
</tr>

<xsl:for-each select="//POINT_RECORDS/POINT_REC[ZIP_CD=$param1]">
<xsl:sort select="CITY_NM"/>

<tr>
  <td style="font-size:8pt" valign="top">
     <xsl:value-of select="CITY_NM"/>
  </td>

  <td style="font-size:8pt" valign="top">
    <xsl:value-of select="STATE_CD"/>
  </td>
</tr>

</xsl:for-each>

</TABLE>    

</xsl:when>

***** THIS PART DOES NOT WORK*********

<xsl:when test="//POINT_RECORDS/POINT_REC[starts-with(ZIP_CD, $param1)]">

<TABLE border="0" width="90%" style="font-size: 10pt" cellspacing="1" cellpadding="1">

<tr>
<th><b>City</b></th>
<th><b>State</b></th>
<th><b>State</b></th>

</tr>

<xsl:for-each select="//POINT_RECORDS/POINT_REC">
<xsl:sort select="ZIP_CD"/>


<tr>
  <td style="font-size:8pt" valign="top">
     <xsl:value-of select="CITY_NM"/>
  </td>

  <td style="font-size:8pt" valign="top">
    <xsl:value-of select="STATE_CD"/>
  </td>

  <td style="font-size:8pt" valign="top">
    <xsl:value-of select="ZIP_CD"/>
  </td>

</tr>

</xsl:for-each>

</TABLE>    

</xsl:when>

<xsl:otherwise>
<p align="center">(No matches found)</p>
</xsl:otherwise>
</xsl:choose>


**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread