Martin,
I'm actually working with XSLT 2.0, so a solution depending on new features is fine.
My current code l is shown below. It does not operate exactly as I would like, though the difference is small. It doesn't use a mode for the first part of the document and I have much more knowledge of the tree elements than I would like in the base template.
The template is actually parsing a modified Word 2007 xml document though I've done a good deal of elimination of elements and changed the namespace prior to invoking this template. This is a stage in which I'm applying some corrections for poor style choices on the part of the document author in preparation for parsing the document itself.
Hope this helps - thanks for suggestions.
--Don
Code:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:g="gptg:PMSA:gptg.net">
<xsl:output method="xml" omit-xml-declaration="no" indent = "yes" encoding = "utf-8"/>
<xsl:strip-space elements="*"/>
<xsl:namespace-alias stylesheet-prefix="w" result-prefix="g"/>
<xsl:namespace-alias stylesheet-prefix="pkg" result-prefix="g"/>
<!-- Default template - handles first part of document and serves as a default mode -->
<!-- **the hard coded position is one of the issues - it corresponds to the node that is splitting the document -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="g:document | g:body | g:paraStyle | g:para[position() < 4] |g:text | text()"/>
</xsl:copy>
</xsl:template>
<!-- template to determine a proper mode for the back portion of the document. -->
<!-- **the hard coded values correspond to the location of this node which should really be identified as the node which
satisfies the match condition -->
<xsl:template match="/g:document/g:body/g:para[substring(normalize-space(g:text[1]),1,7)='Section']">
<xsl:variable name="protocol" select="normalize-space(substring-after(substring-before(g:text[1],':'),'Section'))"/>
<xsl:choose>
<xsl:when test="$protocol='4'">
<xsl:apply-templates select="/g:document/g:body/*[position() > 2]" mode="Pro4"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="/g:document/g:body/*[position() > 2]" mode="None"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- copy template in case there is no real work to be done to the back portion of the document -->
<!-- ** this template is called out separately for purposes of later extension -->
<xsl:template match=" node() | @*" mode="None">
<xsl:copy>
<xsl:apply-templates select="@*" mode="None"/>
<xsl:apply-templates mode="None"/>
</xsl:copy>
</xsl:template>
<!-- copy template for the modal templates that work on the back portion of the document -->
<!-- ** there are many templates matching specific conditions in this mode -->
<xsl:template match="node() | @*" mode="Pro4">
<xsl:copy>
<xsl:apply-templates select="@*" mode="Pro4"/>
<xsl:apply-templates mode="Pro4"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>