Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XSLT: How to write "Yes" if element/attribute exist or "no" if not? (http://www.velocityreviews.com/forums/t167533-xslt-how-to-write-yes-if-element-attribute-exist-or-no-if-not.html)

Mark Richards 07-23-2004 05:51 PM

XSLT: How to write "Yes" if element/attribute exist or "no" if not?
 
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




Martin Honnen 07-24-2004 03:08 PM

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:otherwise>
<xsl:text>noccc</xsl:text>
</xsl:otherwise>
</xsl:choose>

--

Martin Honnen
http://JavaScript.FAQTs.com/



All times are GMT. The time now is 12:34 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57