How to map multiple attributes from source to a multivalued attribute on target in xsl transformations

≡放荡痞女 提交于 2019-12-12 04:47:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!