Subject: Re: [xsl] ancestor/subsequent descendant test From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 27 Mar 2009 17:14:53 +0100 |
My input documents are allowed to contain nested sections. An optional attribute marks out certain sections as significant. I want to detect a situation in which a section which contains a descendant significant section does not contain a subsequent INsignificant section (other than descendants of any significant sections). It's complicated because the nested sections are not (necessarily) immediate descendants of each other.
if the section it is wrapped in did not have the significant attribute set then
I want to report it, because it is INsignificant and a descendant of a
section which contains a prior significant section.
I'm a bit stuck with this template, which identifies the correct ancestor,
It surely isn't as complex as I'm finding it, can anybody help please?
<xsl:template match="section[@sig="Y"]>
T:\>type trevor1.xml <section> <include> <section>.A.</section> <section sig="Y"> <section>.B.</section> <include> <section>.C.</section> </include> </section> <!-- NB --> <section sig="Y"> <section>.D.</section> </section> </include> </section> T:\>xslt2 trevor1.xml trevor.xsl
T:\>type trevor2.xml <section> <include> <section>.A.</section> <section sig="Y"> <section>.B.</section> <include> <section>.C.</section> </include> </section> <!-- NB --> <section> <section>.D.</section> </section> </include> </section> T:\>xslt2 trevor2.xml trevor.xsl Found a problem section: /section[1]/include[1]/section[3]/section[1] T:\>type trevor.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<!--the section is a descendant of a section without significance that has a preceding sibling with significance--> <xsl:template match="section[not(@sig='Y')] [preceding-sibling::section[@sig='Y']]// section"> <xsl:text>Found a problem section: </xsl:text> <!--report the XPath context--> <xsl:for-each select="ancestor-or-self::*"> <xsl:value-of select="concat('/',name(.),'[', count(preceding-sibling::*[node-name(.)= node-name(current())])+1, ']')"/> </xsl:for-each> </xsl:template>
<xsl:template match="/|*"> <xsl:apply-templates select="*"/> </xsl:template>
</xsl:stylesheet> T:\>
-- XSLT/XSL-FO/XQuery training in Los Angeles (New dates!) 2009-06-08 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] ancestor/subsequent descendan, Trevor Nicholls | Thread | RE: [xsl] ancestor/subsequent desce, Trevor Nicholls |
[xsl] ancestor/subsequent descendan, Trevor Nicholls | Date | Re: [xsl] ancestor/subsequent desce, Michael Ludwig |
Month |