下面是一个XSLT2.0解决方案:
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:template match="page">
<xsl:variable name="pages">
<xsl:apply-templates select="." mode="load" />
</xsl:variable>
<xsl:copy>
<h1><xsl:value-of select="header" /></h1>
<!-- you say there is a fixed number of names, so this should be OK -->
<xsl:for-each select="'content-a','content-b','content-c'">
<div>
<xsl:apply-templates select="$pages/page/*[name() = current()]" />
</div>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="page" mode="load">
<xsl:sequence select="." />
<xsl:apply-templates select="document(@include)" mode="load" />
</xsl:template>
<xsl:template match="content-a|content-b|content-c">
<p><xsl:value-of select="." /></p>
</xsl:template>
</xsl:stylesheet>
编辑:对于XSLT1.0,等效解决方案如下所示:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
>
<xsl:template match="page">
<xsl:variable name="pages-rtf"><!-- rtf = result tree fragment -->
<xsl:apply-templates select="." mode="load" />
</xsl:variable>
<xsl:variable name="pages" select="exsl:node-set($pages-rtf)" />
<!-- you say there is a fixed number of names, so this should be OK -->
<xsl:variable name="nodes-rtf">
<content-a/><content-b/><content-c/>
</xsl:variable>
<xsl:variable name="nodes" select="exsl:node-set($nodes-rtf)" />
<xsl:copy>
<h1><xsl:value-of select="header" /></h1>
<xsl:for-each select="$nodes">
<div>
<xsl:apply-templates select="$pages/page/*[name() = name(current())]" />
</div>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="page" mode="load">
<xsl:copy-of select="." />
<xsl:apply-templates select="document(@include)" mode="load" />
</xsl:template>
<xsl:template match="content-a|content-b|content-c">
<p><xsl:value-of select="." /></p>
</xsl:template>
</xsl:stylesheet>