Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] Defining a Section within a Section

From: geoff hopkins <geoffhopkins123@--------->
To:
Date: 11/1/2007 6:56:00 PM
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent