This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: How to find the parent.
- To: Pedro Pastor <pps at ua dot es>
- Subject: Re: [xsl] How to find the parent.
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Fri, 4 May 2001 16:34:30 +0100
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <3AF2C7C8.AAE6DCCF@ua.es>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Pedro,
> I would like to know if it is possible, once you have find a target
> element (whatever kind of element is), to find out which is its
> father.
I always thought of elements as mothers ;)
> A typical example would be looking for a substring and once find it
> getting to know inside which element is included (paragraph, title,
> ...). In fact, as the first query could produce a text-node result
> set, but the actual question would be finding the result set of the
> fathers.
>
> Example:
>
> query = in which elements the string " Shakespeare" is included.
You'd probably be best off getting this by matching all those text
nodes that include the string ' Shakespeare', and then getting their
parent element. You can get the parent with the XPath:
..
And then get its name with the name() function:
<xsl:variable name="query" select="' Shakespeare'" />
<xsl:template match="text()">
<xsl:if test="contains(., $query)">
<xsl:text>Query string contained in:</xsl:text>
<xsl:value-of select="name(..)" />
</xsl:if>
</xsl:template>
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list