This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE:
- From: Stuart Brown <sbrown at extenza dot co dot uk>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Mon, 16 Sep 2002 16:48:33 +0100
- Subject: [xsl] RE:
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Brian,
> I have an XML file with this structure:
>
> <elemA>
> <elemB>
> <elemC></elemC>
> <elemC></elemC>
> etc...
> </elemB>
> <elemB>
> <elemC></elemC>
> <elemC></elemC>
> etc...
> </elemB>
> etc...
> </elemA>
>
> I am writing an XSL file to search it. I want to be able to
> search all of
> the <elemC> nodes for the occurrence of a searchstring - and,
> if an <elemC>
> node matches the searchstring, to output the value of the
> first <elemC> node
> of the <elemB> node that contains the matching <elemC> node.
> I hope that
> makes sense! I haven't been able yet to get the XSL to
> process each of the
> <elemC> nodes of each of the <elemB> nodes systematically.
To rephrase what you want a bit, you want to match/select all the <elemB>
nodes which contain an <elemC> which itself contains the searchstring, and
output the first <elemC> of that element. Try:
<xsl:param name="string" select="'foo'"/>
<xsl:for-each select="elemA/elemB[contains(elemC,$string)]">
<xsl:value-of select="elemC[1]"/>
</xsl:for-each>
Or similar.
Cheers,
Stuart
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list