XSLT: How to write "Yes" if element/attribute exist or "no" if not?

Discussion in 'XML' started by Mark Richards, Jul 23, 2004.

  1. The solutions for the following problems seems to be simple but I did not found a (convenient) solution:
    Assume we have a number of elements of the same type under a common parent e.g.


    <person ... myattr="aaa">Paul</person>
    <person ... myattr="bbb">Peter</person>
    <person ... myattr="ccc">Karl</person>
    .....
    <person ... myattr="ddd">Stan</person>


    Now I want to write a text from inside an XSLT script with the following conditions:

    1.) Write "yesccc" (e.g. into file) if an element <person> with an attribute value myattr="ccc" exist
    otherwise write "noccc"

    2.) Write "yesMick" (e.g. into file) if an element <person> with a value <person ...>Mick</person> exist
    otherwise write "noMick"

    2.) Write "yesAttrib" (e.g. into file) if an element <person> have an attrib myattrib="....." defined
    (value unimportant) otherwise write "noAttrib"

    Thank you for your help

    Mark
    Mark Richards, Jul 23, 2004
    #1
    1. Advertising

  2. Re: XSLT: How to write "Yes" if element/attribute exist or "no" ifnot?

    Mark Richards wrote:

    > The solutions for the following problems seems to be simple but I did
    > not found a (convenient) solution: Assume we have a number of
    > elements of the same type under a common parent e.g.
    >
    >
    > <person ... myattr="aaa">Paul</person> <person ...
    > myattr="bbb">Peter</person> <person ... myattr="ccc">Karl</person>
    > .... <person ... myattr="ddd">Stan</person>
    >
    >
    > Now I want to write a text from inside an XSLT script with the
    > following conditions:
    >
    > 1.) Write "yesccc" (e.g. into file) if an element <person> with an
    > attribute value myattr="ccc" exist otherwise write "noccc"


    <xsl:choose>
    <xsl:when test="//person[@myattr = 'ccc']">
    <xsl:text>yesccc</xsl:text>
    </xsl:choose>
    <xsl:eek:therwise>
    <xsl:text>noccc</xsl:text>
    </xsl:eek:therwise>
    </xsl:choose>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jul 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. Y.S.
    Replies:
    3
    Views:
    990
    strajan
    Sep 17, 2003
  2. anonymous
    Replies:
    1
    Views:
    5,927
  3. teo
    Replies:
    3
    Views:
    520
  4. =?Utf-8?B?TWFyaw==?=
    Replies:
    4
    Views:
    620
    =?Utf-8?B?TWFyaw==?=
    Dec 14, 2006
  5. Jamie Herre
    Replies:
    1
    Views:
    181
    why the lucky stiff
    Jan 7, 2005
Loading...

Share This Page