[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Where text contains() any of a list?

Subject: Where text contains() any of a list?
From: "Steve Muench" <smuench@xxxxxxxxxxxxx>
Date: Mon, 12 Jun 2000 20:14:45 -0400
text.contains
I'm probably looking past something obvious here, but
assuming I have an external document of search terms like:

<!-- terms.xml -->
<terms>
  <term>foo</term>
  <term>bar</term>
</terms>

And a document to transform like:

<doc>
  <para id="1"> this has neither in it </para>
  <para id="2"> this has foo in it </para>
  <para id="3"> this has bar in it </para>
  <para id="4"> this has foo and bar in it </para>
</doc>

How can I find the id's of all the <para>'s that
contains any of the terms/term entries from the
external terms.xml file?

I'd like to use document('terms.xml')/terms/term to
return a nodeset and match <para>'s with id=2, 3, and 4.

contains(x,y) only takes a string for 'y', node a nodelist.

I tinkered with a brute-force way using nested for-each's:

<result xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:variable name="terms" select="document('terms.xml')/terms/term"/>
  <xsl:for-each select="doc/para">
    <xsl:variable name="cur" select="."/>
    <xsl:variable name="matches">
      <xsl:for-each select="$terms">
        <xsl:if test="contains($cur,.)">y</xsl:if>
      </xsl:for-each>
    </xsl:variable>
    <xsl:if test="contains($matches,'y')">
      <id><xsl:value-of select="$cur/@id"/></id>
    </xsl:if>
  </xsl:for-each>
</result>

Which gets the job done, but does't seem that elegant. Any ideas on a terser
solution that could be used in a single XPath expression?
______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
Business Components for Java & XSQL Servlet Development Teams
Oracle Rep to the W3C XSL Working Group
Author "Building Oracle XML Applications", O'Reilly, Oct 2000


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.