[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: choose on element content.

Subject: Re: choose on element content.
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 24 Aug 1999 10:43:18 -0400
xsl when test not
At 99/08/23 16:28 +0100, DPawson@xxxxxxxxxxx wrote:
given
<INDI ID='I001'>
<NAME>John Derek <S>Montalt (Moult)</S></NAME>
<SEX>M</SEX>

I need conditional processing, dependent on the sex of
the NAMEd person.

I'm getting a syntax error with

<xsl:template match="INDI">
 <xsl:choose>
   <xsl:when test="[string(SEX)='M']">
           ^^^^^^^^^^^^^^^^^^ syntax error.^^^^^^^^^^^^^

Predicates are allowed as filters on a node test, not standalone as the above shows.


But predicates aren't what you need ... you can just write an expression that uses the value of the child and compares it to a string. The value is a string already, so no conversions are required.

An example is below ... I hope this helps.

........... Ken


T:\FTEMP>type test.xml <?xml version="1.0"?> <test> <person><sex>M</sex><name>John</name></person> <person><sex>F</sex><name>Jane</name></person> </test> T:\FTEMP>type test.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">

<xsl:template match="/test">
  <xsl:for-each select="person">
    <xsl:choose>
      <xsl:when test="sex='M'">&#xa;Male: </xsl:when>
      <xsl:when test="sex='F'">&#xa;Female: </xsl:when>
      <xsl:otherwise>&#xa;Who knows?: </xsl:otherwise>
    </xsl:choose>
    <xsl:value-of select="name"/>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

T:\FTEMP>call xsl test.xml test.xsl test.txt
T:\FTEMP>type test.txt

Male: John
Female: Jane
T:\FTEMP>

--
G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Website:  XSL/XML/DSSSL/SGML services, training, libraries, products.
Practical Transformation Using XSLT and XPath      ISBN 1-894049-01-2
Next instructor-led training:                     MT'99 1999-12-05/06


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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.