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

Re: Test for presence of attribute

Subject: Re: Test for presence of attribute
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 18 Jul 2001 17:26:17 +0100
xslt test attribute presence
Hi Nathan,

> BUT, URL is not required and if it is not present, then the IF
> statement fails. I need something like IsDefined() or
> AttributeExists()...

You can test for the presence of any node by trying to select it and
converting the result to a boolean. So to test for the attribute @URL
being present, you can use:

  boolean(@URL)

If you're doing this in a context where the expression will be
converted to a boolean anyway, then you don't even have to worry about
the call to boolean(). Just use:

  <xsl:if test="@URL">
    <a href="{@URL}"><xsl:value-of select="@Title" /></a>
  </xsl:if>

Alternatively, apply templates to the URL attribute:

  <xsl:apply-templates select="@URL" />

and have a template that creates the result that you want from it:

<xsl:template match="@URL">
  <a href="{.}"><xsl:value-of select="../@Title" /></a>
</xsl:template>

If the XSLT processor doesn't find a node to apply templates to, then
no template gets applied.

> Also, is there a len() function? I would rather use something like
> <xsl:if test="len(@URL)">...

Try string-length().

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.