xslt and optional attributes

Edwin G. Castro

Usenet Archive
Joined
Sep 16, 2004
Messages
3
Reaction score
0
Is there a way to handle optional attributes in xslt?

I'd like to determine if an attribute exists and do some action if it does. Otherwise, I want to take some other action or simply do nothing.

Thanks!

--Edwin
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
Edwin G. Castro said:
I'd like to determine if an attribute exists and do some action if it does. Otherwise, I want to take some other action or simply do nothing.

Use an XPath that matches the attribute in a test, or that matches an element that has the attribute in a template.

For example, if you have templates

<xsl:template select="foo[@bar]"> ...
and
<xsl:template select="foo"> ...

the first will match <foo>s that have a bar attribute, and the second will match the others. Or you could use a conditional:

<xsl:choose>
<xsl:when test="@bar">
...
</xsl:when>
<xsl:eek:therwise>
...
</xsl:eek:therwise>
</xsl:choose>

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top