XSLT 2.0 XPATH 相交 [英] XSLT 2.0 XPATH intersect

查看:30
本文介绍了XSLT 2.0 XPATH 相交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 XSLT 2.0 下,我正在尝试部署 intersect 以在 XPATH 表达式中使用 xsl:variable.https://xsltfiddle.liberty-development.net/gWmuiK6/1 中的文件(下面是 xslt 中第 175-192 行的问题).

Under XSLT 2.0, I am trying to deploy intersect to use an xsl:variable in an XPATH expression. Files at https://xsltfiddle.liberty-development.net/gWmuiK6/1 (problem below at lines 175-192 in the xslt).

我声明了一个变量:

<xsl:variable name="app-sources" select="tei:del[@rend='expunctus'] | 
    tei:gap | 
    tei:sic | 
    tei:supplied[@reason='added'] | 
    tei:surplus[@reason='repeated' or @reason='surplus']  |
    tei:unclear"></xsl:variable>

我在此处使用该变量与 intersect 并没有输出预期的结果:

And I am using that variable here with intersect, and it does not output the expected result:

 <xsl:template match="*[. intersect $app-sources]">
    <xsl:choose>
        <xsl:when test="self::tei:del[@rend='expunctus']">
            [<xsl:text>EXPUNCTUS</xsl:text>]<xsl:apply-templates/><sup> 
           <xsl:number count="*[. intersect $app-sources]" format="a" level="any"/></sup>
        </xsl:when>
    </xsl:choose>
 </xsl:template>

HTML 中的预期结果[EXPUNCTUS]quondambquandam(在 HTML 输出中的第 465 行附近).

Expected result in HTML[EXPUNCTUS]quondam<sup>b</sup> quandam (around line 465 in the HTML output).

但是如果我替换 *[.将 $app-sources] 与原始 XPATH 相交,它工作正常:

But if I substitute *[. intersect $app-sources] with the original XPATH, it works fine:

 <xsl:template match="tei:del[@rend='expunctus'] | 
    tei:gap | 
    tei:sic | 
    tei:supplied[@reason='added'] | 
    tei:surplus[@reason='repeated' or @reason='surplus']  |
    tei:unclear">
    <xsl:choose>
        <xsl:when test="self::tei:del[@rend='expunctus']">
            [<xsl:text>EXPUNCTUS</xsl:text>]<xsl:apply-templates/><sup> 
           <xsl:number count="tei:del[@rend='expunctus'] | 
                                 tei:gap | 
                                 tei:sic | 
                                 tei:supplied[@reason='added'] | 
                                 tei:surplus[@reason='repeated' or @reason='surplus']  |
                                 tei:unclear" format="a" level="any"/></sup>
        </xsl:when>
    </xsl:choose>
 </xsl:template>

奇怪的是,intersect<xsl:template match="*[.intersect $footnote-sources]" mode="build_footnotes"> 中工作得非常好在上面的代码下方.

Curiously, intersect works perfectly fine in <xsl:template match="*[. intersect $footnote-sources]" mode="build_footnotes"> just below the above code.

推荐答案

如果用

<xsl:variable name="app-sources" select="tei:del[@rend='expunctus'] | 
    tei:gap | 
    tei:sic | 
    tei:supplied[@reason='added'] | 
    tei:surplus[@reason='repeated' or @reason='surplus']  |
    tei:unclear"></xsl:variable>

tei:del 这样的所有路径都用于选择主输入文档节点作为上下文节点,并且您的主输入文档具有 TEI 根元素但肯定没有 delgap 或任何其他元素作为文档节点的子节点.因此,您需要确保使用诸如 //tei:del//dei:gap 之类的路径来选择主输入文档所用名称的任何后代元素.

all your paths like tei:del are used to select with the primary input document node as the context node and your primary input document has a TEI root element but certainly no del or gap or any of the other elements as child nodes of the document node. So you will need to make sure you use paths like //tei:del or //dei:gap to select any descendants elements of the used name of the primary input document.

当然,由于您还使用由模式创建的临时文档,因此对于该变量,您可能不想选择主要输入文档的后代,而是从另一个变量中的临时结果中选择后代,所以在在这种情况下,您需要使用例如$foo//tei:gap 在您的路径表达式中选择绑定到 app-sources 变量的节点.

Of course as you are also using temporary documents created by modes it might be that for that variable you don't want to select descendants of the primary input document but rather ones from a temporary result you have in another variable, so in that case you would need to use e.g. $foo//tei:gap in your path expressions selecting the nodes bound to the app-sources variable.

这篇关于XSLT 2.0 XPATH 相交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆