【发布时间】:2020-12-04 17:15:29
【问题描述】:
我有这个 XML:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<txnId>0</txnId>
<headerNotes>
<reservationId>505524998</reservationId>
<computerId>93725091</computerIdId>
<customerNumber>2166552</customerNumber>
<modifiedDate>2015-07-27T13:36:19.000+0000</modifiedDate>
<modifiedBy>sa_oapig</modifiedBy>
<requestedBy>sa_oapig</requestedBy>
<serialNumber>1</serialNumber>
<note/>
<headerSummary>
<reserve>Reservation info</reserve>
<actionTaken>Changed</actionTaken>
</headerSummary>
<headerDetails>
<reserve>Reservation info</reserve>
<actionBy/>
<field/>
<original/>
<new/>
</headerDetails>
</headerNotes>
</Root>
我想使用 XSLT 转换将上述 XML 转换为新的 SOAP 格式, 这里主要是我不需要根元素和headerNotes,但需要它的子元素,另一个条件是headerNotes 三个子元素应该再次嵌入到它们自己的标签中,如下面的要求所示。 我需要确切的 XSLT 代码来转换到肥皂信封内的 XML 之下
<reservationId>505524998</reservationId>
<computerId>93725091</computerIdId>
<customerNumber>2166552</customerNumber>
<modifiedDate>2015-07-27T13:36:19.000+0000</modifiedDate>
<modifiedBy>sa_oapig</modifiedBy>
<requestedBy>sa_oapig</requestedBy>
<serialNumber>1</serialNumber>
<note/>
<headerSummary>
<reserve>Reservation info</reserve>
<actionTaken>Changed</actionTaken>
</headerSummary>
<headerDetails>
<reserve>Reservation info</reserve>
<actionBy/>
<field/>
<original/>
<new/>
</headerDetails>
我尝试过使用下面的 xslt 代码,但没有成功
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>
<xsl:template match="Root">
<xsl:for-each select="/Root/headerNotes">
<reservationId>
<reservationId><xsl:value-of select="reservationId" /> </reservationId>
</reservationId>
<computerId>
<computerId> <xsl:value-of select="computerId" /> </computerId>
</computerId>
<customerNumber>
<customerId><xsl:value-of select="customerNumber"/></customerId>
</customerNumber>
</xsl:for-each>
</xsl:template>
<xsl:template match="headerNotes">
<xsl:copy-of select="./*" />
</xsl:template>
<xsl:template match="headerSummary">
<xsl:copy-of select="." />
</xsl:template>
<xsl:template match="headerDetails">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
我正在寻找可用于在我的代码中使用它的 xslt 代码。一旦我有了解决方案,它将有助于我的转型。
谢谢
【问题讨论】:
-
您确定这正是您想要的结果吗?没有单个根元素的 XML 片段?
-
我想将此输出转换为 SOAP 正文。请帮帮我
-
我在你的输出中没有看到 SOAP,所以不清楚你想要什么。
-
我将硬核soap标签并希望将xslt转换放入soap body