Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xslt and optional attributes

Reply
Thread Tools

xslt and optional attributes

 
 
Edwin G. Castro
Guest
Posts: n/a
 
      09-24-2004
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
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      09-24-2004
In article <(E-Mail Removed) >,
Edwin G. Castro <(E-Mail Removed)> wrote:

>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>
<xsltherwise>
...
</xsltherwise>
</xsl:choose>

-- Richard

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT adding children in an optional structure Herman Slagman XML 1 05-28-2009 10:24 AM
WebControl.Attributes.Add and custom attributes P4trykx ASP .Net 2 01-31-2007 04:33 PM
xerces-2j and qualified optional default attributes Robert W. XML 2 10-19-2006 10:06 PM
XSLT optional attributes Eric Anderson XML 4 10-08-2004 01:13 PM
Correct way to handle optional attributes in JSP custom tag handler Bruce Atherton Java 1 01-15-2004 02:22 AM



Advertisments