【问题标题】:Is it possible to use an xsl function to set the value of an xml element's attribute?是否可以使用 xsl 函数来设置 xml 元素属性的值?
【发布时间】:2013-11-08 08:07:19
【问题描述】:

美好的一天!

因此,我一直在寻找解决方案,以解决我在与 SAP Business One 集成框架的集成项目中遇到的问题。

总而言之,我需要传递一个 xsl 函数的值作为 xml 元素属性的值。

因此:(或者更确切地说,这就是我想要实现的目标)

<Party role=<xsl:value-of select="$msg/BOM/BO/BPAddresses/row/AddressType"/>>
    <PartyIDs>
      blahblah

我想知道。是否可以将变量传递给属性? 有点新的 xslt 和很多..所以任何建议将不胜感激。 提前谢谢!

【问题讨论】:

    标签: xml xslt xml-attribute


    【解决方案1】:

    您需要在这里使用Attribute Value Templates。这是您要查找的语法

    <Party role="{$msg/BOM/BO/BPAddresses/row/AddressType}">
        <PartyIDs>
           blahblah
    

    花括号表示要计算的表达式,而不是字面意义上的输出。

    请注意,您也可以使用 xsl:attribute 命令

    <Party>
        <xsl:attribute name="role">
            <xsl:value-of select="$msg/BOM/BO/BPAddresses/row/AddressType"/>
        <xsl:attribute>
        <PartyIDs>
           blahblah
    

    但是正如您所看到的,这有点冗长,属性值模板通常是要走的路。

    【讨论】:

    • 完美!也谢谢你的建议! +1!
    猜你喜欢
    • 1970-01-01
    • 2017-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多