xsl-list
[Top] [All Lists]

Re: [xsl] Multiple arguments in one test

2010-11-16 14:30:00
On 11/16/2010 12:48 PM, Sharon_Harris(_at_)ultimatesoftware(_dot_)com wrote:
How do I perform a test to find an element whose attribute value equals a
specific value and if the element itself contains specific text? For
example, I want to find a "p" element that has an "outputclass" attribute
whose value is "SupportInfo" and when those conditions are met, does that
"p" element contain the keyword "Yes". And once all of those conditions are
met, then do something (for example, output "this works").

XML snippet:
-------------------
<p outputclass="SupportInfo">Yes</p>


I have tried combining all arguments into 1 test but the latter part of the
test is ignored.

XSLT snippet:
---------------------
<xsl:choose>
      <xsl:when test="//@outputclass='SupportInfo' and contains(., 'Yes')">

The problem here is that the context for the contains(., 'Yes') is not
the same as the context for @outputclass.
Thus the above expression is asking, in effect, "Is there an
@outputclass attribute anywhere (on any kind of element) with a value of
'SupportInfo', and does the current context node (having no relationship
to any aforementioned @outputclass attributes) have a string value
containing 'Yes'?"

What you probably want instead is something like

<xsl:choose>
        <xsl:when test="@outputclass='SupportInfo' and contains(., 'Yes')">

assuming that this code appears inside a for-each or apply-templates
that is selecting p elements.

"//" at the beginning of an XPath expression means "any descendant of
the root of the document containing the context node". If you were
trying to use this to output something for p anywhere in the document,
you'll need to use a for-each or apply-templates select="//p".

Lars


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>