[Home] [By Thread] [By Date] [Recent Entries]
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="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>
"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
|

Cart



