使用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]))"/>