[xsl] Defining a Section within a Section

Subject: [xsl] Defining a Section within a Section
From: geoff hopkins <geoffhopkins123@xxxxxxxxx>
Date: Thu, 1 Nov 2007 11:55:49 -0700 (PDT)
Using XSLT2.0, Saxon8



The input XML is part of a larger document and I have
had to cut it for privacy reasons.



My objective is to separate a particular section from
the rest of the document.



The rule I am trying to apply is to separate the
section 'Package...XZ' to the first instance of
'Internal Interface' from the rest of the document. 
Then separate that section further by defining two
sections before 'Provided Subprograms' and after
'Provided Subprograms'.



In XML v1 - It produces the output required.



In XML v2 it fails due to the second Provided
Subprograms later in the document. If <xsl:template
match="data"/> had some processing the  

this template would work.



I thought (incorrectly!!?!) that as I had defined my
first section it would not consider the rest of the
document when applying the rule on the template
implementing mode-first....



Can anyone advise?



Sorry it's long but did not want to provide a
incomplete message for help.

Geoff



----------

Input XML v1

----------

<?xml version="1.0" encoding="ISO-8859-1"?>

<root>

<data></data>

<data></data>

<data></data>

<data> </data>

<data></data>

<data></data>

<data>sample data</data>

<data></data>

<data>   end if</data>

<data></data>

<data>2.5	Package MyPackageXZ</data>

<data>2.5.1	Description</data>

<data>This class provides the</data>

<data></data>

<data></data>

<data></data>

<data>2.5.2	Diagram</data>

<data> </data>

<data></data>

<data></data>

<data>2.5.3	Interface</data>

<data>Not withstanding the visibility</data>

<data>2.5.3.1	Provided Types</data>

<data>Name        : </data>

<data></data>

<data></data>

<data>2.5.3.2	Provided Constants</data>

<data>None.</data>

<data>2.5.3.3	Provided Data</data>

<data>None.</data>

<data>2.5.3.4	Provided Subprograms</data>

<data>The</data>

<data>section</data>

<data>I</data>

<data>am</data>

<data>interested</data>

<data>in</data>

<data>2.5.4	Internal Interface</data>

<data>Not withstanding the visibility.....</data>

<data>of this package.</data>

<data>2.5.4.1	Internal Types</data>

<data>Name        : MyNewType</data>

<data>Description : None.</data>

<data></data>

<data>2.6.3.2	Provided Constants</data>

<data>None.</data>

<data>2.6.3.3	Provided Data</data>

<data>None.</data>

<data>the</data>

<data>rest</data>

<data>of</data>

<data>the</data>

<data>document</data>

</root>



----------

XSL

----------



<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="xml" indent="yes"/>



	<xsl:template match="root">

		<root>

			<xsl:apply-templates select="data"/>

			

		</root>

	</xsl:template>

	

	<xsl:template
match="data[matches(normalize-space(.),'^([0-9]+\.?)+\sPackage\s[A-Za-z]+XZ$','i')]">

		<xsl:apply-templates
select="following::data[following::data[matches(normalize-space(.),'^([0-9]+\.?)+\sInternal\sInterface$','i')]]"
mode="first" />

	</xsl:template>



	<xsl:template
match="data[following-sibling::data[matches(normalize-space(.),'^([0-9]+\.?)+\sProvided\sSubprograms$','i')]]"
mode="first"/>

	

	<xsl:template match="data" mode="first">

		<a>

			<xsl:value-of select="."/>

		</a>	

	</xsl:template>

	

	<xsl:template match="data"/>

	

	

</xsl:stylesheet>

----------

OUTPUT - XML

----------

<root>

   <a>2.5.3.4	Provided Subprograms</a>

   <a>The</a>

   <a>section</a>

   <a>I</a>

   <a>am</a>

   <a>interested</a>

   <a>in</a>

</root>





----------

Input XML v2

----------

<?xml version="1.0" encoding="ISO-8859-1"?>

<root>

<data></data>

<data></data>

<data></data>

<data> </data>

<data></data>

<data></data>

<data>sample data</data>

<data></data>

<data>   end if</data>

<data></data>

<data>2.5	Package MyPackageXZ</data>

<data>2.5.1	Description</data>

<data>This class provides the</data>

<data></data>

<data></data>

<data></data>

<data>2.5.2	Diagram</data>

<data> </data>

<data></data>

<data></data>

<data>2.5.3	Interface</data>

<data>Not withstanding the visibility</data>

<data>2.5.3.1	Provided Types</data>

<data>Name        : </data>

<data></data>

<data></data>

<data>2.5.3.2	Provided Constants</data>

<data>None.</data>

<data>2.5.3.3	Provided Data</data>

<data>None.</data>

<data>2.5.3.4	Provided Subprograms</data>

<data>The</data>

<data>section</data>

<data>I</data>

<data>am</data>

<data>interested</data>

<data>in</data>

<data>2.5.4	Internal Interface</data>

<data>Not withstanding the visibility.....</data>

<data>of this package.</data>

<data>2.5.4.1	Internal Types</data>

<data>Name        : MyNewType</data>

<data>Description : None.</data>

<data></data>

<data>2.6.3.2	Provided Constants</data>

<data>None.</data>

<data>2.6.3.3	Provided Data</data>

<data>None.</data>

<data>2.6.3.4	Provided Subprograms</data>

<data>the</data>

<data>rest</data>

<data>of</data>

<data>the</data>

<data>document</data>

</root>



----------

OUTPUT - XML

----------

<?xml version="1.0" encoding="UTF-8"?>

<root/>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Current Thread