xsl-list
[Top] [All Lists]

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

2006-06-15 11:30:25
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

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

<Prev in Thread] Current Thread [Next in Thread>