问题
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>
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>
I tried with simple for-each, but this is not getting the values.
Sample transformation code :
<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>
How is it possible to get all the group
in values
?
回答1:
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>
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.
来源:https://stackoverflow.com/questions/25759154/how-to-map-multiple-attributes-from-source-to-a-multivalued-attribute-on-target