Altova Mailing List Archives

RE: [xsl] if condition

From: "Michael Kay" <mike@------------>
Date: 3/9/2005 10:30:00 PM
Here's one way:

<xsl:template match="customer">
  <xsl:attribute name="age">unknown</xsl:attribute>
  <xsl:copy-of select="@age"/>

this relies on the fact that if you add two attributes with the same name to
a result element, the last one wins.

A more conventional solution is

  <xsl:when test="@age"><xsl:copy-of select="@age"/></xsl:when>
  <xsl:otherwise><xsl:attribute name="age".....

Michael Kay

> -----Original Message-----
> From: Bhaskar, Rajan [mailto:RBhaskar@xxxxxxx] 
> Sent: 09 March 2005 21:16
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> 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">


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.