Subject: Re: [xsl] Applying templates to all but descendant-or-self:: From: "Spencer Tickner" <spencertickner@xxxxxxxxx> Date: Thu, 15 Jun 2006 13:23:04 -0800 |
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?
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Applying templates to all, Jagdishwar B | Thread | Re: [xsl] Applying templates to all, Jagdishwar B |
Re: [xsl] Applying templates to all, Jagdishwar B | Date | [xsl] Selecting all nodes between p, Duncan Anker |
Month |