RE: [xsl] ancestor/subsequent descendant test, problem restated

Subject: RE: [xsl] ancestor/subsequent descendant test, problem restated
From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx>
Date: Mon, 30 Mar 2009 03:26:29 +1300
Hi Ken

The stylesheet you wrote has identified a problem in the simple example;
unfortunately my simple example evidently isn't sufficiently true to life,
because it didn't pick up hanging content in a real example.

I really appreciate that you have continued offering help here and I'm sorry
if it looks as though I keep changing the terms of the problem; I'm not,
honest!

Here follows a tree extracted from a real file which really has a problem.
Here it is the section contained within the included "abc_config_file.xml"
element, because this section will produce a separate result document, and
section content both before and after it will go into the result document
produced by the first section inside the included "abc.xml" element.

====

cat trevor.xml
<?xml version="1.0" encoding="UTF-8"?>
<document>
	<included srcfile="introduction.xml">
		<section sig="Y">
			<section/>
		</section>
	</included>
	<included srcfile="abc.xml">
		<section sig="Y">
			<included srcfile="abc_intro.xml">
				<section/>
			</included>
			<included srcfile="abc_config.xml">
				<section>
					<included
srcfile="abc_config_file.xml">
						<section sig="Y">
							<section>
								<section>
	
<section/>
								</section>
								<section/>
							</section>
						</section>
					</included>
					<included
srcfile="abc_config_reloc.xml">
						<section>
							<section/>
							<section/>
						</section>
					</included>
				</section>
			</included>
			<included srcfile="abc_remove.xml">
				<section/>
			</included>
			<included srcfile="abc_web.xml">
				<section>
					<included
srcfile="abc_web_grouping.xml">
						<section>
							<included
srcfile="abc_web_grp_intro.xml">
								<section/>
							</included>
							<included
srcfile="abc_web_grp_create.xml">
								<section>
	
<section/>
	
<section/>
								</section>
							</included>
							<included
srcfile="abc_web_grp_add.xml">
								<section>
	
<section/>
	
<section/>
								</section>
							</included>
							<included
srcfile="abc_web_grp_nest.xml">
								<section>
	
<section/>
	
<section/>
								</section>
							</included>
						</section>
					</included>
					<included srcfile="abc_motd.xml">
						<section>
							<included
srcfile="abc_motd_display.xml">
								<section/>
							</included>
							<included
srcfile="abc_motd_edit.xml">
								<section/>
							</included>
						</section>
					</included>
				</section>
			</included>
			<included srcfile="abc_security.xml">
				<section>
					<section>
						<section/>
					</section>
				</section>
			</included>
		</section>
	</included>
</document>

====

Because this generated file has stripped out all the content inside the
sections, including the ids, I modified your XSL to use the srcfile of the
nearest ancestral "included" element, which on reflection is probably how I
would choose to report the problem to the authors anyway.

====

cat trevor.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:output method="text"/>

<xsl:template match="/">
	<xsl:for-each
select="//section[not(@sig='Y')][preceding-sibling::section/@sig='Y']">
		<xsl:variable name="probf"
select="ancestor::included[1]/@srcfile" />
Problem section found in: <xsl:value-of select="$probf"/>
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

====

I think the preceding-sibling test would work if I could somehow strip out
any "included" elements in the tree before evaluating the "sibling"
sections. Unfortunately I can't rely on there being zero, one, two, or any
number of nested "included" elements complicating the
[sibling/*-nephew/*-uncle] relationship.

Thanks, trying not to be demanding
Trevor

Current Thread