看起来你只要选对就行了
paragraph
<xsl:template match="sentence">
<xsl:copy>
<xsl:apply-templates
select="@*,
$paragraph-doc/paragraphs/paragraph[xs:integer(@parBegin) <= xs:integer(current()/@sentBegin) and xs:integer(@parEnd) >= xs:integer(current()/@sentEnd)]/(@id, @par_type)"/>
</xsl:copy>
</xsl:template>
在下面,我将段落文档内联到一个参数中,但是您当然可以使用
doc
功能:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="paragraph-doc">
<paragraphs>
<paragraph id="par_1" parBegin="1" parEnd="100" par_type="intro" context="positive"/>
<paragraph id="par_2" parBegin="101" parEnd="170" par_type="elaboration" context="negative"/>
<paragraph id="par_3" parBegin="171" parEnd="210" par_type="elaboration" context="positive"/>
<paragraph id="par_4" parBegin="211" parEnd="280" par_type="conclusion" context="neutral"/>
</paragraphs>
</xsl:param>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="sentence">
<xsl:copy>
<xsl:apply-templates
select="@*,
$paragraph-doc/paragraphs/paragraph[xs:integer(@parBegin) <= xs:integer(current()/@sentBegin) and xs:integer(@parEnd) >= xs:integer(current()/@sentEnd)]/(@id, @par_type)"/>
</xsl:copy>
</xsl:template>
<xsl:template match="paragraph/@id">
<xsl:attribute name="paragraph" select="."/>
</xsl:template>
</xsl:stylesheet>
https://xsltfiddle.liberty-development.net/nc4NzQZ
是XSLT 3示例,对于XSLT 2,您需要替换使用的
xsl:mode
作为上述的改进或替代,我们可以
上的元素
@parBegin to @parEnd
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="paragraph-doc">
<paragraphs>
<paragraph id="par_1" parBegin="1" parEnd="100" par_type="intro" context="positive"/>
<paragraph id="par_2" parBegin="101" parEnd="170" par_type="elaboration" context="negative"/>
<paragraph id="par_3" parBegin="171" parEnd="210" par_type="elaboration" context="positive"/>
<paragraph id="par_4" parBegin="211" parEnd="280" par_type="conclusion" context="neutral"/>
</paragraphs>
</xsl:param>
<xsl:key name="par-ref" match="paragraph" use="@parBegin to @parEnd"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="sentence">
<xsl:copy>
<xsl:apply-templates
select="@*,
key('par-ref', xs:integer(@sentEnd), $paragraph-doc)/(@id, @par_type)"/>
</xsl:copy>
</xsl:template>
<xsl:template match="paragraph/@id">
<xsl:attribute name="paragraph" select="."/>
</xsl:template>
</xsl:stylesheet>
https://xsltfiddle.liberty-development.net/nc4NzQZ/2