是否可以使用xsl函数来设置xml元素属性的值?

时间:2022-11-28 11:13:11

Good Day!

美好的一天!

So I've been looking around to for a solution to a problem I have in an integration project with SAP Business One Integration framework.

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

The long and short of it is that I need to pass the value of an xsl function to serve as the value for an xml element's attribute.

它的长和短是我需要传递xsl函数的值作为xml元素属性的值。

As such:(Or rather, this is what I'm trying to achieve)

(或者更确切地说,这就是我想要达到的目标)

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

I was wondering. Is it possible to maybe pass a variable to the attribute instead? Kinda new to xslt and the lot..so any advice would be appreciated. Thank you in advance!

我在想。是否可以将变量传递给属性?xslt和其他东西有点新。因此,任何建议都会受到欢迎。提前谢谢你!

1 个解决方案

#1


4  

You need to use Attribute Value Templates here. This is the syntax you looking for

您需要在这里使用属性值模板。这是您要查找的语法

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

The curly braces indicates an expression to be evaluated, rather than output literalally.

花括号表示要计算的表达式,而不是直接输出。

Note that you can also use the xsl:attribute command

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

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

But as you can see this is a bit more verbose, and Attribute Value Templates are usually the way to go.

但是正如您所看到的,这有点冗长,属性值模板通常是一种方法。

#1


4  

You need to use Attribute Value Templates here. This is the syntax you looking for

您需要在这里使用属性值模板。这是您要查找的语法

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

The curly braces indicates an expression to be evaluated, rather than output literalally.

花括号表示要计算的表达式,而不是直接输出。

Note that you can also use the xsl:attribute command

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

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

But as you can see this is a bit more verbose, and Attribute Value Templates are usually the way to go.

但是正如您所看到的,这有点冗长,属性值模板通常是一种方法。