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

Subject: Re: [xsl] Applying templates to all but descendant-or-self::
From: "Jagdishwar B" <jagdishwar.beemanati@xxxxxxxxx>
Date: Thu, 15 Jun 2006 22:27:36 +0200
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