使用Muenchian法一群儿童document
可以通过第一前Br
:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="byPosition" match="/document/*[not(self::Br)]"
use="generate-id(preceding-sibling::Br[1])"/>
<xsl:template match="@*|node()" name="identity" priority="-5">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/document/*[not(self::Br) and
generate-id()=generate-id(key('byPosition',
generate-id(preceding-sibling::Br[1]))[1])]">
<p><xsl:copy-of
select="key('byPosition',
generate-id(preceding-sibling::Br[1]))"/></p>
</xsl:template>
<xsl:template match="/document/*" priority="-3"/>
</xsl:stylesheet>
说明:
<xsl:key name="byPosition" match="/document/*[not(self::Br)]"
use="generate-id(preceding-sibling::Br[1])"/>
:首先,项基于其第一在前
Br
元件上在
key
分组
身份转换用于通过不变的方式复制大多数节点:
<xsl:template match="@*|node()" name="identity" priority="-5">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
然后我们相匹配的是其key
的第一个此类项目的document
所有的孩子:
<xsl:template match="document/*[not(self::Br) and
generate-id()=generate-id(key('byPosition',
generate-id(preceding-sibling::Br[1]))[1])]">
...和使用,作为在该点复制由key
分组的所有项目:
<xsl:copy-of select="key('byPosition',
generate-id(preceding-sibling::Br[1]))"/>