如何在 xsl 转换中将多个属性从源映射到目标上的多值属性 [英] How to map multiple attributes from source to a multivalued attribute on target in xsl transformations
问题描述
我必须使用 xsl 转换来从一个 wsdl 映射到另一个.在我的源 wsdl 中,我有一个具有多个值的属性,例如源 wsdl 的结果是
I have to use xsl transformations for mapping from one wsdl to another.In my source wsdl I have an attribute which has multiple values for example the result from the sorce wsdl is
<Groups>
<group>Group1</group>
<group>Group2</group>
</Groups>
在目标 wsdl 中 this 要映射到的属性的类型是:
The type of the attribute to which this is to be mapped in the target wsdl is :
<xs:complexType name="attributesMultiValued">
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="values" type="xs:string"
nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
我尝试使用简单的 for-each,但这并没有得到值.
I tried with simple for-each, but this is not getting the values.
示例转换代码:
<attributesMultiValued>
<name>
<xsl:text disable-output-escaping="no">Groups</xsl:text>
</name>
<xsl:for-each select="tns:Groups">
<values>
<xsl:value-of select="group"/>
</values>
</xsl:for-each>
</attributesMultiValued>
如何获取values
中的所有group
?
推荐答案
看起来这就是您要执行的操作:
It looks like this is what you're trying to do:
<attributesMultiValued>
<name>Groups</name>
<xsl:for-each select="tns:Groups/tns:Group">
<values>
<xsl:value-of select="." />
</values>
</xsl:for-each>
</attributesMultiValued>
更好的方法是使用模板:
A better approach is to use templates:
<attributesMultiValued>
<name>Groups</name>
<xsl:apply-templates select="tns:Groups/tns:Group" />
</attributesMultiValued>
<!-- A bit further down... -->
<xsl:template match="tns:Group">
<values>
<xsl:value-of select="." />
</values>
</xsl:template>
但是,如果没有更广泛的 XML 示例(例如,tns:
命名空间来自何处?未显示在您的示例 XML 中.
However, I can't be sure that either of these is what you need without a more extensive example of your XML (for example, where is the tns:
namespace coming from? It's not shown in your example XML.
这篇关于如何在 xsl 转换中将多个属性从源映射到目标上的多值属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!