|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Test for presence of attribute
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








