xslt/saxon - 将 key() 与 collection() 结合使用:prolog 中不允许使用内容?
xslt/saxon - using key() with collection() : content is not allowed in prolog?
我在 file:///Users/username/foopath
收集了一系列 tei-xml 文档。我需要通过 XSLT 2.0 转换访问这些文档以获得密钥。
我有一个密钥,可以在 //tei:seg[@type='dep_event']/@corresp
的那些文档中搜索匹配项
因此,我为文档集合声明了一个变量:
<xsl:variable name="coll"
select="collection('file:///Users/username/foopath')"/>
还有一把钥匙:
<xsl:key name="correspidkey"
match="tei:seg[@type='dep_event' and @corresp]"
use="@corresp"></xsl:key>
然后我按如下方式针对集合部署密钥(拒绝来自 self::
的任何不需要的 returns):
<xsl:variable name="correspvar"
select="self::seg[@type='dep_event' and @corresp]/@corresp"/>
<xsl:value-of select="$coll/(key('correspidkey',$correspvar)
except $correspvar)/upper-case(@id)"
separator=", "/>
</xsl:element>
</xsl:when>
Saxon HE 9.6.07 returns Content is not allowed in prolog
,但我无法确定此错误的确切含义。如果我删除这一行,错误就会消失并且文件处理正常。也许我使用 collection()
和密钥?
非常感谢。
错误是因为您在 collection()
上的调用选择了格式不正确的文件 XML。您可以 (a) 在集合 URI 中使用 ;select=*.xml
或 (b) 使用 ;on-error=ignore
.
过滤掉非 XML 文件
我在 file:///Users/username/foopath
收集了一系列 tei-xml 文档。我需要通过 XSLT 2.0 转换访问这些文档以获得密钥。
我有一个密钥,可以在 //tei:seg[@type='dep_event']/@corresp
因此,我为文档集合声明了一个变量:
<xsl:variable name="coll"
select="collection('file:///Users/username/foopath')"/>
还有一把钥匙:
<xsl:key name="correspidkey"
match="tei:seg[@type='dep_event' and @corresp]"
use="@corresp"></xsl:key>
然后我按如下方式针对集合部署密钥(拒绝来自 self::
的任何不需要的 returns):
<xsl:variable name="correspvar"
select="self::seg[@type='dep_event' and @corresp]/@corresp"/>
<xsl:value-of select="$coll/(key('correspidkey',$correspvar)
except $correspvar)/upper-case(@id)"
separator=", "/>
</xsl:element>
</xsl:when>
Saxon HE 9.6.07 returns Content is not allowed in prolog
,但我无法确定此错误的确切含义。如果我删除这一行,错误就会消失并且文件处理正常。也许我使用 collection()
和密钥?
非常感谢。
错误是因为您在 collection()
上的调用选择了格式不正确的文件 XML。您可以 (a) 在集合 URI 中使用 ;select=*.xml
或 (b) 使用 ;on-error=ignore
.