xslt and optional attributes

Discussion in 'XML' started by Edwin G. Castro, Sep 24, 2004.

  1. 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
    Edwin G. Castro, Sep 24, 2004
    #1
    1. Advertising

  2. In article <>,
    Edwin G. Castro <> 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>
    <xsl:eek:therwise>
    ...
    </xsl:eek:therwise>
    </xsl:choose>

    -- Richard
    Richard Tobin, Sep 24, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruce Atherton
    Replies:
    1
    Views:
    567
    Bruce Atherton
    Jan 15, 2004
  2. Eric Anderson

    XSLT optional attributes

    Eric Anderson, Oct 8, 2004, in forum: XML
    Replies:
    4
    Views:
    2,025
    Eric Anderson
    Oct 8, 2004
  3. P4trykx
    Replies:
    2
    Views:
    1,787
    bruce barker
    Jan 31, 2007
  4. Robert W.
    Replies:
    2
    Views:
    383
    Robert W.
    Oct 19, 2006
  5. Herman Slagman
    Replies:
    1
    Views:
    1,082
    Martin Honnen
    May 28, 2009
Loading...

Share This Page