This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How to find the parent.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]