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
I'm probably looking past something obvious here, but
assuming I have an external document of search terms like:

<!-- terms.xml -->

And a document to transform like:

  <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>

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:if test="contains($matches,'y')">
      <id><xsl:value-of select="$cur/@id"/></id>

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