Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - xpath ancestors [Thread Next] Re: xpath ancestorsTo: NULL Date: 1/10/2008 3:42:00 PM
Chuck Jungmann wrote:
> <banking>
> <bank name="WF">
> <account name="checking"/>
> <account name="saving"/>
^^^^^^^^^^^^^^^^^^^^^^^^
> <account name="mortgage"/>
> </bank>
> <bank name="BankOne">
> <account name="brokerage"/>
> <account name="creditcard"/>
> </bank>
> </banking>
> <xsl:variable
> name="demoNode"
> select="/banking/bank[@name='WF']/account[@name='saving']" />
This selects one account element, marked above.
>
> <xsl:variable
> name="anc"
> select="$demoNode/ancestor-or-self::node()" />
This selects nodes of any kind (node()) on the ancestor-or-self axis so
it selects the account element, its parent, the bank element, the
grandparent, the banking element (which is the root element), and the
root node (/, the document node). That way you get four nodes.
> <xsl:template match="/">
> <html>
> <head><title>xpath demo</title></head>
> <body>
> <p>
> Expecting 3 nodes in ancestor-or-self, getting
> <xsl:value-of select="count($anc)" /> (four) instead.
If you are only interested in element nodes then use
ancestor-or-self::*, that way you get three elements.
HTH
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
