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

Re: if condition

Subject: Re: if condition
From: JBryant@xxxxxxxxx
Date: Wed, 9 Mar 2005 15:36:29 -0600
if condition in xsl
Something like these two templates:

  <xsl:template match="customer[@age]">
    <xsl:copy-of select="."/>
  </xsl:template>

  <xsl:template match="customer[not(@age)]">
    <customer name="{@name}" age="unknown"/>
  </xsl:template>

OR something like this one:

  <xsl:template match="customer">
    <customer name="{@name}">
      <xsl:choose>
        <xsl:when test="@age">
          <xsl:attribute name="age">
            <xsl:value-of select="@age"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="age">unknown</xsl:attribute>
        </xsl:otherwise>
      </xsl:choose>
    </customer>
  </xsl:template>

Tested on Saxon8.

HTH

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




"Bhaskar, Rajan" <RBhaskar@xxxxxxx> 
03/09/2005 03:15 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
<xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
cc

Subject
 if condition






Hi,
 How can i do a if condition in XSLT when a particular attribute/element
in xml is not present and else with a default string

<customer name="xy" age="30">

say incase age is not present. i want to replace with "unknown"
<customer name="xy" age="unknown">

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.