xsl-list
[Top] [All Lists]

Re: if condition

2005-03-09 14:36:29
Something like these two templates:

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

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

OR something like this one:

  <xsl:template match="customer">
    <customer name="{(_at_)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(_at_)cvs(_dot_)com> 
03/09/2005 03:15 PM
Please respond to
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com


To
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
cc

Subject
[xsl] 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">

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>