[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Applying templates to all but descendant-or-self::

Subject: Re: Applying templates to all but descendant-or-self::
From: "Spencer Tickner" <spencertickner@xxxxxxxxx>
Date: Thu, 15 Jun 2006 13:23:04 -0800
xsl apply templates not self
Hi Jag,

Thanks for the post. The above stylesheet doesn't quite do it. It
drops the sectionnumber and sectiontext from the output. I should also
mention the reason I was using descendant-or-self:: in each of the
templates above is because <change> can be wrapped around any of the
elements, not just the descendants of <section>.

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?

Thanks,

Spencer


On 6/15/06, Jagdishwar B <jagdishwar.beemanati@xxxxxxxxx> wrote:
For this kind of solutions, if you use descendant:: or
descendant-or-self:: axes, it will match many elements under the
tree... it will become little hard and tricky to understand.

In your xsl,
under <xsl:template match="section">,
the
<xsl:apply-templates select="*[not(descendant-or-self::sectionnumber
or descendant-or-self::sectiontext)]"/>
is not matching the <change> element,


It can be resolved by using child::elementName axes or just using elementName.


Try the below xsl:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:variable name="cr">
                <xsl:text>
</xsl:text>
        </xsl:variable>
        <xsl:variable name="tab">
                <xsl:text>     </xsl:text>
        </xsl:variable>
        <xsl:template match="/">
                <root>
                        <xsl:value-of select="$cr"/>
                        <xsl:apply-templates/>
                </root>
        </xsl:template>
        <xsl:template match="section">
                <HED2>Section <xsl:apply-templates select="sectionnumber"/>
                        <xsl:text>
</xsl:text>
                        <xsl:apply-templates select="sectiontext"/>
                </HED2>
                <xsl:value-of select="$cr"/>
                <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match="sectionnumber">
                <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match="sectiontext">
                <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match="subsection">
                <HED3>
                        <xsl:apply-templates select="subsectionnumber"/>
                        <xsl:value-of select="$tab"/>
                        <xsl:apply-templates select="subsectiontext"/>
                </HED3>
                <xsl:value-of select="$cr"/>
                <xsl:apply-templates select="*[not(self::subsectionnumber or
self::subsectiontext)]"/>
        </xsl:template>
        <xsl:template match="subsectionnumber">
                <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match="subsectiontext">
                <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match="article">
                <HED4>
                        <xsl:apply-templates select="articlenumber"/>
                        <xsl:value-of select="$tab"/>
                        <xsl:apply-templates select="articletext"/>
                </HED4>
                <xsl:value-of select="$cr"/>
                <xsl:apply-templates select="*[not(self::articlenumber or
self::articletext)]"/>
        </xsl:template>
        <xsl:template match="articlenumber">
                <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match="articletext">
                <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match="change">
                <xsl:apply-templates select="*[not(self::sectionnumber or
self::sectiontext)]"/>
        </xsl:template>
</xsl:stylesheet>

Kind Regards,
Jagdishwar B.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.