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

M

Mark Richards

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
 
M

Martin Honnen

Mark said:
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>
 

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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top