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

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

Subject: Applying templates to all but descendant-or-self::
From: "Spencer Tickner" <spencertickner@xxxxxxxxx>
Date: Thu, 15 Jun 2006 09:36:30 -0800
xslt select descendant
Hi List,

Thanks in advance for any help.

I have a template where changes are indicated with a <change> element.
For the particular transformation I'm doing I don't care if something
is changed or not. My current stylesheet is dropping information, and
I can't quite figure out why.

--------------------------------------------------------------------------------------------

XML

<?xml version="1.0"?>
<section qpid="ep001014.10">
					<change>
							<sectionnumber>2.10.</sectionnumber>
							<sectiontext>Community Care Facilities</sectiontext>
							<subsection qpid="ep001014.10.1">
								<subsectionnumber>2.10.1.</subsectionnumber>
								<subsectiontext>Construction</subsectiontext>
								<article qpid="ea002081">
									<articlenumber>2.10.1.1.</articlenumber>
									<articletext>Construction</articletext>
								</article>
							</subsection>
					</change>
							<subsection qpid="ep001014.10.2">
								<subsectionnumber>2.10.2.</subsectionnumber>
								<subsectiontext>Staffing</subsectiontext>
								<article qpid="ea002082">
									<articlenumber>2.10.2.1.</articlenumber>
									<articletext>Staffing</articletext>
								</article>
							</subsection>
						
</section>

--------------------------------------------------------------------------------------------

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="descendant::sectionnumber"/><xsl:text>
</xsl:text><xsl:apply-templates
select="descendant::sectiontext"/></HED2><xsl:value-of select="$cr"/>
<xsl:apply-templates select="*[not(descendant-or-self::sectionnumber
or descendant-or-self::sectiontext)]"/>
</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="descendant::subsectionnumber"/><xsl:value-of
select="$tab"/><xsl:apply-templates
select="descendant::subsectiontext"/></HED3><xsl:value-of
select="$cr"/>
<xsl:apply-templates
select="*[not(descendant-or-self::subsectionnumber or
descendant-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="descendant::articlenumber"/><xsl:value-of
select="$tab"/><xsl:apply-templates
select="descendant::articletext"/></HED4><xsl:value-of select="$cr"/>
<xsl:apply-templates select="*[not(descendant-or-self::articlenumber
or descendant-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/></xsl:template>

</xsl:stylesheet>

--------------------------------------------------------------------------------------------

Current Output

<?xml version='1.0' ?>
<root>
<HED2>Section 2.10. Community Care Facilities</HED2>
<HED3>2.10.2.	Staffing</HED3>
<HED4>2.10.2.1.	Staffing</HED4>
</root>


As you can see <subsection> 2.10.1. is being dropped along with <article> 2.10.1.1. This must have something to do my apply-templates="*[not(descendant-or-self:: ...." but from my understanding on this it means:

"apply all templates except for the next <number> or <text> element
whether it is the next child or descendant of the calling element"

which is why I can't understand why after the section element it
doesn't go on to process the change element, skip the sectiontext and
sectionnumber element and go on to process the subsection element.

I'm using Saxon and using XSLT 2.0 is fine.

Thanks,

Spencer

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.