xsl-list
[Top] [All Lists]

Re: [xsl] Applying templates to all but descendant-or-self::

2006-06-16 08:23:31
Hi Jagdishwar,

Thanks for the post.

in your case, the
<xsl:apply-templates select="*[not(descendant-or-self::sectionnumber
or descendant-or-self::sectiontext)]"/>
will not match <change> element because,
when <change> is the context node, it satisfies the predicate
(descendant-or-self::sectionnumber or descendant-or-self::sectiontext)
as <change> itself has sectionnumber and sectiontext as descendents.

After looking and thinking about this statement closely I can kind-of
see where you're coming from. Of course you're right, I've done a
couple of tests just to prove it to myself. But it still doesn't sit
well with me. If I <xsl:apply-templates
match="descendant-or-self::sectionnumber"/> I would not expect (nor
should I) to match any <change> elements. Even though as your
statement above indicates the <change> element satisfies the predicate
when it's the context node. Why then when using the same statement
using not() would I not get <change> elements?

i think you can achieve what you are looking for, by using
<xsl:apply-templates select="*[not(self::sectionnumber or self::sectiontext)]"/>
it will match all the children of <section> exept sectionnumber and sectiontext.

This is true, however it still matches the "descendants" sectionnumber
and sectiontext when the <change> element is in context of the
<section> element, so instead of dropped elements I end up with
duplications.

(It does work with your original xsl post but I had to change

<xsl:template match="change">
              <xsl:apply-templates select="*[not(self::sectionnumber or 
self::sectiontext)]"/>
</xsl:template>

to <xsl:template match="change"><xsl:apply-templates</xsl:template>

because as I mentioned before the <change> elements can enclose any
elements within my xml document, not just children of <section>)


Thanks again for the post, if you have any other ideas or thoughts I
would love to hear them. In the end I may have to just resort to an
ugly choose statement.

Thanks,

Spencer


On 6/15/06, Jagdishwar B <jagdishwar(_dot_)beemanati(_at_)gmail(_dot_)com> 
wrote:
Hi,

>
> I'm still rather confused by the reason that <xsl:apply-templates
> select="*[not(descendant-or-self::sectionnumber or
> descendant-or-self::sectiontext)]"/> would not match the <change>
> element. I wonder if you could shed any light on this?

in your case, the
<xsl:apply-templates select="*[not(descendant-or-self::sectionnumber
or descendant-or-self::sectiontext)]"/>
will not match <change> element because,
when <change> is the context node, it satisfies the predicate
(descendant-or-self::sectionnumber or descendant-or-self::sectiontext)
as <change> itself has sectionnumber and sectiontext as descendents.
and, not(descendant-or-self::sectionnumber or
descendant-or-self::sectiontext) is giving false when <change> is the
context node, so it is not getting matched.

i think you can achieve what you are looking for, by using
<xsl:apply-templates select="*[not(self::sectionnumber or self::sectiontext)]"/>
it will match all the children of <section> exept sectionnumber and sectiontext.

Kind Regards,
Jagdishwar.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>