使用xsl模板的奇怪行为

时间:2015-09-03 19:04:31

标签: xml xslt

我有一段通过xquery生成的XML,我试图将xsl样式表应用到它上面。我知道样式表适用于我用来构建查询的xml文件,但我不确定为什么它不适用于我生成的xml:

我在其中一个源文档中有以下xml:

<zone n="EETS.QD.4">
<line n="l.1">
    <orig><hi>O</hi> alle ye <gap quantity="8" unit="chars" reason="illegible"
    />s of ierusaleem<note place="bottom" anchored="true"
        xml:id="explanatory">The “l” in “ierusaleem” in the final word is
        determined from context.</note></orig>
</line>

在xquery生成的文档中,这与其他文档中的行组合以获得以下内容:

<list xml:id="compare">
            <item>
                <orig>London, British Library Harley 2251: <ref target=".html">O alle ye doughtres · of Jerusalem</ref>
                </orig>
            </item>
            <item>
                <orig>London, British Library Harley 2255: <ref target=".html">
                    <hi rend="blue_pilcrow">¶</hi>O alle ye douħtren of <hi rend="underline">ierusaleem</hi>
                </ref>
                </orig>
            </item>
            <item>
                <orig>Long Melford, Holy Trinity Church Clopton Chantry Chapel: <ref target=".html">
                    <hi>O</hi> alle ye <gap quantity="8" unit="chars" reason="illegible"/>s of ierusaleem<note place="bottom" anchored="true" xml:id="explanatory">The “l” in “ierusaleem” in the final word is
                        determined from context.</note>
                </ref>
                </orig>
            </item>
            <item>
                <orig>Cambridge, Jesus College Q.G.8: <ref target=".html">
                    <hi>A</hi>ll the <hi rend="underline">doughtren </hi>of <hi rend="underline">Ierusalem</hi> .</ref>
                </orig>
            </item>
            <item>
                <orig>Oxford, Bodleian Library Laud 683: <ref target=".html">O alle ẏe douhtren of jerusaleem</ref>
                </orig>
            </item>
        </list>

在这两种情况下都应用以下模板:

<xsl:template match="tei:orig/tei:gap">
    <xsl:text>[</xsl:text>
    <xsl:variable name="max" select="@quantity"/>
    <xsl:for-each select="1 to $max">
        <xsl:text>.</xsl:text>
    </xsl:for-each>
    <xsl:text>]</xsl:text>
</xsl:template>

在标准文档中,它会正确显示我想要的内容:

O alle ye [........]s of ierusaleem

但是当应用于生成的文档时,我得到以下内容:

O alle ye s of ierusaleem

很明显,它没有找到子节点,但我不确定为什么因为模板是从orig标签起作用的。

我遇到的第二个问题是我无法通过xquery或xslt获取note元素,但我怀疑它与gap这个问题有关。任何建议都将不胜感激,谢谢!

1 个答案:

答案 0 :(得分:0)

注意:这个问题的答案不是我的,并在评论中给出。为了完整性并考虑回答的问题,我在这里添加它,因为问题不再可删除。

  

我没有看到任何BERDecode元素...... ^

Michael Kay

  

在XQuery生成的文档中,gap不是gap的孩子;它是orig的孩子。 ^

Daniel Haley

都指向同一问题,导致OP的代码失败。换句话说,XPath没有选择任何东西,因为元素的路径不正确。