Re: [xsl] Exclusions in XPATH

Subject: Re: [xsl] Exclusions in XPATH
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 21 Nov 2002 15:24:53 +0000
Hi Robin,

> XSL:
>                 <xsl:template match="A">
>                         <xsl:for-each
> select="./*[1]//*[not(*)]|./*[1]//@*[not(*)]">   
>                                 <xsl:value-of select="name()"/> 
>                                 <xsl:if test="position()!=last()">;</xsl:if>
>
>                         </xsl:for-each> 
>                 <xsl:apply-templates/> 
>         </xsl:template>
>
> Question 1: Can I get both attribute-names and element-names more
> easily in the select or does it have to be like I have it above ?

You can probably simplify the expression you're using to select the
elements and attributes to:

  .//*[not(*)] | .//@*

I say probably because (a) your path only looks at the descendants of
the first child of the <A> element, whereas the above looks at all
descendants of the <A> element and (b) your path wouldn't pick the <B>
element if it only held text, whereas mine would.
  
> If I only know the element-names A and F
>
> Question 2: How can I exclude the descendants of element F from the
> select ? Output would then be C;E;W. I've tried various combinations
> but either end up with all-or-nothing.

I think that the easiest way would be to add a filter to the
expression to only select those nodes that do not have the <F> element
as an ancestor:

  (.//*[not(*)] | .//@*)[not(ancestor::F)]

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread