xsl-list
[Top] [All Lists]

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

2006-06-15 14:23:25
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(_dot_)beemanati(_at_)gmail(_dot_)com> 
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.

--~------------------------------------------------------------------
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>
--~--