【问题标题】:XSLT 2.0 using key with except returns unexpected resultXSLT 2.0 使用带有 except 的键返回意外结果
【发布时间】:2018-10-22 20:58:53
【问题描述】:

注意:更改了标题以更好地反映问题。

我的 xml 文档包含一个元素 <tei:seg @type @xml:id @corresp>,它包装了一些小“故事”。 @corresp 属性允许我将这些故事连接到一个主故事。比如这些seg都是由它们的@corresp连接的:

doc1.xml//seg[@type='dep_event' @corresp='#JKL' @xml:id='doc1-05']
doc2.xml//seg[@type='dep_event' @corresp='#JKL' @xml:id='doc2-06']
doc6.xml//seg[@type='dep_event' @corresp='#JKL' @xml:id='doc6-03']

我的目标是:当XSLT模板找到@corresp时,在其他具有相同@corresp的文档中找到其他seg并输出各自的`@xml:id`

所以,在上面的例子中,如果当前的seg@xml:id='doc1-05',那么模板输出一个列表:Corresponds to doc2-06, doc6-03

直到我可以解决 eXist-DB 中的 current problems with XSLT collection() 之前,我将退回到我之前的解决方案:一个“TEI corpus”xml 文档,它通过 xi:include 维护所有相关 tei-xml 文档的主列表。这样,我提供了一个文档节点,处理器可以访问和搜索所有 xml 文档。

所以,我声明语料库文件:

<xsl:variable name="corpus" select="doc('ms609_corpus.xml')"/>

然后为@corresp 创建一个key

<xsl:key name="correspkey" match="//tei:seg[@type='dep_event' and @corresp]" use="@corresp"/>

然后我使用带有doc() 的密钥进行搜索:

<xsl:when test="tei:seg[@type='dep_event' and @corresp]">
     <xsl:variable name="correspvar" 
        select="data(self::seg[@type='dep_event' and @corresp]/@corresp)"/>
     <xsl:text>Corresponds to </xsl:text>
     <xsl:value-of select="data($corpus/(key('correspkey',$correspvar) except $correspvar)/@xml:id)" separator=", "/>
</xsl:when> 

它返回结果,但except 应该排除当前的@corresp。但它包含在结果中。

【问题讨论】:

    标签: xslt xslt-2.0


    【解决方案1】:

    except 运算符根据节点身份处理节点序列,请参阅 https://www.w3.org/TR/xpath20/#combining_seq 定义

    except 运算符将两个节点序列作为操作数并返回一个 序列包含第一个操作数中出现的所有节点,但 不在第二个操作数中...所有这些运算符都消除了重复 基于节点身份的结果序列中的节点

    基于此,我认为您只是想要

     <xsl:value-of select="$corpus/(key('correspkey', current()/@corresp) except current())/@xml:id)" separator=", "/>
    

    在将节点原子化为值的节点上使用data,然后尝试在节点上使用except,这对我来说似乎没有意义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-14
      • 2017-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多