M 试图将 shipfromlocationref 换成 shiptolocationref 以获得以下 XML
M trying to swap shipfromlocationref to shiptolocationref for the below XML
我正在尝试交换下面 XML 中的两个值,
在我下面 xml ShipFromLocationRef 的值为 RO91,ShipToLocationRef 的值为 6449706。我的要求是将 R091 换成 ShipToLocationRef 和 6449706 到 ShipFromLocationRef.
请求您在此提供帮助
下面是我的XML我想要转化的
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Transmission xmlns="http://www.w3.org/1999/XSL/Transform">
<TransmissionHeader>
</TransmissionHeader>
<TransmissionBody>
<GLogXMLElement>
<Release>
<ReleaseGid>
<Gid>
<DomainName>M02</DomainName>
<Xid>4008060679_XD</Xid>
</Gid>
</ReleaseGid>
<TransactionCode>IU</TransactionCode>
<ShipFromLocationRef>
<LocationRef>
<LocationGid>
<Gid>
<DomainName>M02</DomainName>
<Xid>RO91</Xid>
</Gid>
</LocationGid>
</LocationRef>
</ShipFromLocationRef>
<ShipToLocationRef>
<LocationRef>
<LocationGid>
<Gid>
<DomainName>M02</DomainName>
<Xid>6449706</Xid>
</Gid>
</LocationGid>
</LocationRef>
</ShipToLocationRef>
</Release>
</GLogXMLElement>
</TransmissionBody>
</Transmission>
Belo 是我的 XSL 代码:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:Transmission="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Transmission:ShipFromLocationRef/LocationRef/LocationGid/Gid/Xid">
<xsl:copy>
<xsl:apply-templates select="@*|../Transmission:ShipToLocationRef/LocationRef/LocationGid/Gid/Xid/text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Transmission:ShipToLocationRef/LocationRef/LocationGid/Gid/Xid">
<xsl:copy>
<xsl:apply-templates select="@*|../Transmission:ShipFromLocationRef/LocationRef/LocationGid/Gid/Xid/text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我的预期输出是:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Transmission xmlns="http://www.w3.org/1999/XSL/Transform">
<TransmissionHeader>
</TransmissionHeader>
<TransmissionBody>
<GLogXMLElement>
<Release>
<ReleaseGid>
<Gid>
<DomainName>M02</DomainName>
<Xid>4008060679_XD</Xid>
</Gid>
</ReleaseGid>
<TransactionCode>IU</TransactionCode>
<ShipFromLocationRef>
<LocationRef>
<LocationGid>
<Gid>
<DomainName>M02</DomainName>
<Xid>**6449706**</Xid>
</Gid>
</LocationGid>
</LocationRef>
</ShipFromLocationRef>
<ShipToLocationRef>
<LocationRef>
<LocationGid>
<Gid>
<DomainName>M02</DomainName>
<Xid>**RO91**</Xid>
</Gid>
</LocationGid>
</LocationRef>
</ShipToLocationRef>
</Release>
</GLogXMLElement>
</TransmissionBody>
</Transmission>
AFAICT,这 returns 预期结果:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ns0:ShipFromLocationRef//ns0:Xid">
<xsl:copy>
<xsl:value-of select="//ns0:ShipToLocationRef//ns0:Xid"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ns0:ShipToLocationRef//ns0:Xid">
<xsl:copy>
<xsl:value-of select="//ns0:ShipFromLocationRef//ns0:Xid"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我正在尝试交换下面 XML 中的两个值, 在我下面 xml ShipFromLocationRef 的值为 RO91,ShipToLocationRef 的值为 6449706。我的要求是将 R091 换成 ShipToLocationRef 和 6449706 到 ShipFromLocationRef.
请求您在此提供帮助 下面是我的XML我想要转化的
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Transmission xmlns="http://www.w3.org/1999/XSL/Transform">
<TransmissionHeader>
</TransmissionHeader>
<TransmissionBody>
<GLogXMLElement>
<Release>
<ReleaseGid>
<Gid>
<DomainName>M02</DomainName>
<Xid>4008060679_XD</Xid>
</Gid>
</ReleaseGid>
<TransactionCode>IU</TransactionCode>
<ShipFromLocationRef>
<LocationRef>
<LocationGid>
<Gid>
<DomainName>M02</DomainName>
<Xid>RO91</Xid>
</Gid>
</LocationGid>
</LocationRef>
</ShipFromLocationRef>
<ShipToLocationRef>
<LocationRef>
<LocationGid>
<Gid>
<DomainName>M02</DomainName>
<Xid>6449706</Xid>
</Gid>
</LocationGid>
</LocationRef>
</ShipToLocationRef>
</Release>
</GLogXMLElement>
</TransmissionBody>
</Transmission>
Belo 是我的 XSL 代码:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:Transmission="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Transmission:ShipFromLocationRef/LocationRef/LocationGid/Gid/Xid">
<xsl:copy>
<xsl:apply-templates select="@*|../Transmission:ShipToLocationRef/LocationRef/LocationGid/Gid/Xid/text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Transmission:ShipToLocationRef/LocationRef/LocationGid/Gid/Xid">
<xsl:copy>
<xsl:apply-templates select="@*|../Transmission:ShipFromLocationRef/LocationRef/LocationGid/Gid/Xid/text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我的预期输出是:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Transmission xmlns="http://www.w3.org/1999/XSL/Transform">
<TransmissionHeader>
</TransmissionHeader>
<TransmissionBody>
<GLogXMLElement>
<Release>
<ReleaseGid>
<Gid>
<DomainName>M02</DomainName>
<Xid>4008060679_XD</Xid>
</Gid>
</ReleaseGid>
<TransactionCode>IU</TransactionCode>
<ShipFromLocationRef>
<LocationRef>
<LocationGid>
<Gid>
<DomainName>M02</DomainName>
<Xid>**6449706**</Xid>
</Gid>
</LocationGid>
</LocationRef>
</ShipFromLocationRef>
<ShipToLocationRef>
<LocationRef>
<LocationGid>
<Gid>
<DomainName>M02</DomainName>
<Xid>**RO91**</Xid>
</Gid>
</LocationGid>
</LocationRef>
</ShipToLocationRef>
</Release>
</GLogXMLElement>
</TransmissionBody>
</Transmission>
AFAICT,这 returns 预期结果:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ns0:ShipFromLocationRef//ns0:Xid">
<xsl:copy>
<xsl:value-of select="//ns0:ShipToLocationRef//ns0:Xid"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ns0:ShipToLocationRef//ns0:Xid">
<xsl:copy>
<xsl:value-of select="//ns0:ShipFromLocationRef//ns0:Xid"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>