Reputation: 13
I'm trying to do SOAP to XML transformation in XSLT 2.0, this is the source xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xi="http://www.xcdm.com">
<soapenv:Header/>
<soapenv:Body>
<xi:root>
<xmlHeader>
<timestamp>1232135468</timestamp>
<source>xds unit</source>
</xmlHeader>
<xmlBody>
<method>create</method>
<customer>
<custA>VOC-Prov</custA>
<custB>vocprov</custB>
</customer>
<Item>
<subElmt1>12345</subElmt1>
<subElmt2>534321</subElmt2>
</Item>
</xmlBody>
</xi:root>
</soapenv:Body>
`
I have been looking for days for a way to transform the structure using XSLT 2.0 so that the output will structured by this one :
<customer version="1.0">
<custA>VOC-Prov</custA>
<custB>vocprov</custB>
<Item name="constName" method="value from the method element (create)">
<Attribute name="subElmt1">value of subElmt1 element</Attribute>
<Attribute name="subElmt2">534321</Attribute>
</Item>
</customer>
Any help on this would be greatly appreciated!
Upvotes: 0
Views: 5573
Reputation: 116958
I have been looking for days for a way to transform the structure
Not sure why you're having such trouble with this, as it seems like a relatively easy task:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<customer version="1.0">
<xsl:variable name="body" select="//xmlBody" />
<xsl:copy-of select="$body/customer/*" copy-namespaces="no"/>
<Item name="constName" method="{$body/method}">
<xsl:for-each select="$body/Item/*">
<Attribute name="{name()}">
<xsl:value-of select="." />
</Attribute>
</xsl:for-each>
</Item>
</customer>
</xsl:template>
</xsl:stylesheet>
Upvotes: 3