xml 使用 xslt 2.0 进行转换
xml transformation using xslt 2.0
我正在尝试在 XSLT 2.0 中进行 SOAP 到 XML 的转换,这是来源 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>
`
几天来我一直在寻找一种使用 XSLT 2.0 转换结构的方法,以便输出将以此结构化:
<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>
- 如何在请求的 xml 结果中将方法值作为属性连接起来?
- 实现将元素转换为与此 xml hirarchiel 匹配的属性的 xslt 的最佳方法是什么?
如有任何帮助,我们将不胜感激!
I have been looking for days for a way to transform the structure
不确定您为什么遇到这样的麻烦,因为这似乎是一项相对容易的任务:
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>
我正在尝试在 XSLT 2.0 中进行 SOAP 到 XML 的转换,这是来源 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>
`
几天来我一直在寻找一种使用 XSLT 2.0 转换结构的方法,以便输出将以此结构化:
<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>
- 如何在请求的 xml 结果中将方法值作为属性连接起来?
- 实现将元素转换为与此 xml hirarchiel 匹配的属性的 xslt 的最佳方法是什么?
如有任何帮助,我们将不胜感激!
I have been looking for days for a way to transform the structure
不确定您为什么遇到这样的麻烦,因为这似乎是一项相对容易的任务:
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>