【问题标题】:XSL Template passing path as stringXSL 模板将路径作为字符串传递
【发布时间】:2014-06-26 09:32:25
【问题描述】:

我正在尝试将 xml 路径作为字符串传递给模板。

<xsl:call-template name="checkPath">
    <xsl:with-param name="path" select="'parent/child1'" />
</xsl:call-template>

在模板中,我将一个子元素附加到传递的字符串中,以检查是否存在具有路径和给定名称的子元素。

<xsl:template name="checkPath">
    <xsl:param name="path"/>
    <xsl:variable name="childElement" select="child-name"/>
    <xsl:if test="$path/child2[name=$childElement]">
         //Do some processing.  
    </xsl:if>
</xsl:template>

上面的 XSL 给了我以下错误。

Invalid conversion from 'java.lang.String' to 'node-set'.

我正在尝试解析以下 XML。

<parent>
    <child1>
        <child2>
            <name>name1</name>
        </child2>
    </child1>
</parent>

.....
<child-name>name1</child-name>

【问题讨论】:

    标签: xml xslt transform


    【解决方案1】:

    不要将路径作为字符串传递,只需删除引号并传递路径选择的实际节点集。

    <xsl:call-template name="checkPath">
        <xsl:with-param name="path" select="parent/child1" />
    </xsl:call-template>
    

    【讨论】:

      猜你喜欢
      • 2019-02-11
      • 1970-01-01
      • 2010-12-25
      • 1970-01-01
      • 1970-01-01
      • 2021-01-28
      • 1970-01-01
      • 2011-01-03
      • 1970-01-01
      相关资源
      最近更新 更多