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 --> <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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Generating Test Data, Mike Brown | Thread | RE: Where text contains() any of a , Kay Michael |
Generating Test Data, Nick Browne | Date | Re: Problem using XSL, juggy |
Month |