作为参数的属性在xsl中返回空值:XSLT中的contains()

时间:2015-10-23 10:47:49

标签: xslt

变量$ authors声明如下:

<listAuthor>
    <author catalogNumber="26A.18.1" fullName="Pjotr Domanski"/>
    <author catalogNumber="26A.19.1" fullName="Hermine Rex"/>
    <author catalogNumber="26A.19.2" fullName="Christoferus Hohenzell"/>
</listAuthor>

此外,还提供了以下XML输入:

<h1:Block Type="obj">
  <h1:Field Type="5000" Value="77772001" />
  <h1:Field Type="5209" Value="26A.19.1 : Lazy Tennis"/>
</h1:Block>

预期输出为:

<h1:Block Type="obj">
  <h1:Field Type="5000" Value="77772001" />
  <h1:Field Type="5209" Value="26A.19.1 : Lazy Tennis"/>
  <h1:Field Type="9904" Value="Hermine Rex"/>
</h1:Block>

以下是我转型的片段:

<xsl:template match="h1:Block">
    <h1:Block Type="obj">
        <xsl:copy-of select="child::*"/>
        <h1:Field Type="9904">
            <xsl:attribute name="Value"
               select="$authors/listAuthor/author[contains (h1:Field[@Type='5209']/@Value, @catalogNumber)]/@fullName"/>
        </h1:Field>
    </h1:Block>
</xsl:template>

@catalogNumber 时,作者姓名应放在 h1:字段[@Type =&#39; 9904&#39;] / @ Value $ authors / author 包含在 h1:字段[@Type =&#39; 5209&#39;] 中。不幸的是, @Value 属性仍为空。

我通过引入变量找到了以下解决方法:

<xsl:template match="h1:Block">
    <h1:Block Type="obj">
        <xsl:copy-of select="child::*"/>
        <xsl:variable name="value5209" select="h1:Field[@Type='5209']/@Value"/>
        <h1:Field Type="9904">
            <xsl:attribute name="Value"
               select="$authors/listAuthor/author[contains ($value5209, @catalogNumber)]/@fullName"/>
        </h1:Field>
    </h1:Block>
</xsl:template>

在这种情况下,它工作正常。有没有人知道为什么它在第一种情况下不起作用?我使用Saxon Saxon-HE 9.6。

1 个答案:

答案 0 :(得分:0)

在谓词中,上下文节点是没有author的{​​{1}}元素,因此将h1:Field更改为$authors/listAuthor/author[contains (h1:Field[@Type='5209']/@Value, @catalogNumber)]/@fullName以选择模板的上下文节点。