|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Matching on text after embedded elements
Hi Bruce,
> I am writing a search engine for a XML file. I am having a problem
> figuring out the correct XSL to get the "contains" to find text
> after a child element. This is the example XML file (TMX format).
>
> <tmx><body>
>
> <tu>
> <tuv lang="JA"><seg></seg></tuv>
> <tuv lang="EN-US"><seg>XXX<ut>eeee</ut>YYY</seg></tuv>
> </tu>
>
> </body></tmx>
>
> In this case if I search for "XXX", my search algorithm works. But
> if I enter "YYY" it fails. I have determined that my algorithm fails
> if it tries to find something after the first child element ("<ut>")
> occurs.
Note that "XXX" is the value of the *first* text node within the <seg>
element, whereas "YYY" is the *last* text node within the <seg>
element. You're doing:
> Here is the XSL code:
>
> <xsl:template match="tu">
> <xsl:if test="tuv/seg[contains (text(), $SearchText)] or
> $SearchText=''">
You're testing whether the <tu> element contains a <tuv> element that
contains a <seg> element whose *first* text node contains $SearchText.
Why is it only looking at the first text node? Because the first
argument to the contains() function is a string, and when you convert
a node set to a string, you get the first node in the node set.
I'm not sure what you're wanting to do. If you want to include the
text within the <ut> element in your search, you should use:
<xsl:if test="tuv/seg[contains(., $SearchText)]">
...
</xsl:if>
If you're not interested in the text inside the <ut> element, then
look at the values of the text() nodes with:
<xsl:if test="tuv/seg/text()[contains(., $SearchText)]">
...
</xsl:if>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








