contains(//section[1]/title[1]/content-style[1]/text(),'ORDER')
You do a contains
on the whole path, explicitly saying, in this expression, to get the first of each element with [1]
. Instead, from your description you want the child content-style
that has "ORDER" in it, which you should do as follows:
//section[1]/title[1]/content-style[text() = 'ORDER']
Or, if whitespace can be added:
//section[1]/title[1]/content-style[normalize-space(text()) = 'ORDER']
If the result is non-empty, you have found at least one "ORDER" in any content-style
below title[1]
, below section[1]
.
get grand child text from grand parent element
This was your question title. It is slightly different from what you wrote. If you want to check for any grand-child content-style
from section
then do this:
//section[1]/*/content-style[normalize-space(text()) = 'ORDER']
Final note: you tagged your original question as xslt, in XSLT, an if-condition does not need to be a boolean, so:
<xsl:if test="//section[1]/*/content-style[normalize-space(text()) = 'ORDER']">
<hello>found it!</hello>
</xsl:if>
is equal to wrapping the whole thing in contains
, except that with contains
you would be checking to a string combined of all elements, which would also mach 'no such ORDER', for instance.
The above is also similar to:
<!-- in place of xsl;if -->
<xsl:apply-templates select="//section[1]/*/content-style" />
<!-- place this at root level anywhere -->
<xsl:template match="content-style[normalize-space(text()) = 'ORDER']">
<hello>found it!</hello>
</xsl:template>
<xsl:template match="content-style">
<hello>Not an order!</hello>
</xsl:template>