コーディングを始めたばかりです。属性値の設定が機能していないようで、外側の for-each ループ内の参照ノードの子ノードにアクセスしていません。コードの何が問題なのかわかりません。
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<B2BGatewayDoc>
<Document>
<xsl:copy-of select="/B2BGatewayDoc/Document/ServiceHeader" />
<ServiceContent>
<Transmission>
<TransmissionBody>
<xsl:copy-of select="/B2BGatewayDoc/Document/ServiceContent/Transmission/TransmissionBody/ReceiverSystem" />
<xsl:for-each select="/B2BGatewayDoc/Document/ServiceContent/Transmission/TransmissionBody/GLogXMLElement" >
<GLogXMLElement>
<ActualShipment>
<xsl:attribute name="xmlns" >
<xsl:value-of select="ActualShipment/@xmlns" />
</xsl:attribute>
<Shipment>
<xsl:copy-of select="ActualShipment/Shipment/ShipmentHeader" />
<xsl:for-each select="ActualShipment/Shipment/TransOrder" >
<TransOrder>
<xsl:copy-of select="TransOrderHeader" />
</TransOrder>
</xsl:for-each>
</Shipment>
</ActualShipment>
</GLogXMLElement>
</xsl:for-each>
</TransmissionBody>
</Transmission>
</ServiceContent>
</Document>
</B2BGatewayDoc>
</xsl:template>
</xsl:stylesheet>
XML サンプル
<?xml version="1.0"?>
<B2BGatewayDoc>
<Document>
<ServiceHeader>
<Protocol name="ANSIX12">
<Sender>941714834TEST</Sender>
<Receiver>003897733SAPT</Receiver>
<MsgType>3A4MG2</MsgType>
<ReferenceNumber/>
<PipVersion>V02.02</PipVersion>
<InstanceIdentifier/>
</Protocol>
</ServiceHeader>
<ServiceContent>
<Transmission>
<TransmissionBody>
<ReceiverSystem>
<ReceiverSystemName>XXXXX</ReceiverSystemName>
<ReceiverSystemName>YYYYY</ReceiverSystemName>
</ReceiverSystem>
<GLogXMLElement>
<ActualShipment xmlns="1000181ZZZ">
<Shipment>
<ShipmentHeader>
<ShipmentGid>
<Gid>
<Xid>1000181ZZZ</Xid>
</Gid>
</ShipmentGid>
<ShipmentRefnum>
<ShipmentRefnumQualifierGid>
<Gid>
<Xid>SELLER_INV_NBR</Xid>
</Gid>
</ShipmentRefnumQualifierGid>
<ShipmentRefnumValue>VALUE 1</ShipmentRefnumValue>
</ShipmentRefnum>
<ShipmentRefnum>
<ShipmentRefnumQualifierGid>
<Gid>
<Xid>SHIP_TYPE</Xid>
</Gid>
</ShipmentRefnumQualifierGid>
<ShipmentRefnumValue>O</ShipmentRefnumValue>
</ShipmentRefnum>
<TransactionCode>IU</TransactionCode>
<TotalShipUnitCount>1</TotalShipUnitCount>
<TotalPackagedItemSpecCount>1</TotalPackagedItemSpecCount>
<CommercialTerms>
<IncoTermGid>
<Gid>
<Xid>EXW</Xid>
</Gid>
</IncoTermGid>
</CommercialTerms>
<NumOrderReleases>1</NumOrderReleases>
<VesselGid>
<Gid>
<Xid>BOL54891</Xid>
</Gid>
</VesselGid>
</ShipmentHeader>
<TransOrder>
<TransOrderHeader>
<TransOrderGid>
<Gid>
<Xid>BR20000238</Xid>
</Gid>
</TransOrderGid>
<CommercialTerms>
<IncoTermGid>
<Gid>
<Xid>EXW</Xid>
</Gid>
</IncoTermGid>
</CommercialTerms>
<TransportModeGid>
<Gid>
<Xid>H</Xid>
</Gid>
</TransportModeGid>
<ModeProfileGid>
<Gid>
<Xid/>
</Gid>
</ModeProfileGid>
<OrderRefnum>
<OrderRefnumQualifierGid>
<Gid>
<Xid>BOL</Xid>
</Gid>
</OrderRefnumQualifierGid>
<OrderRefnumValue>BOL54891</OrderRefnumValue>
</OrderRefnum>
<OrderRefnum>
<OrderRefnumQualifierGid>
<Gid>
<Xid>CUST_PO_NBR</Xid>
</Gid>
</OrderRefnumQualifierGid>
<OrderRefnumValue>4700175047</OrderRefnumValue>
</OrderRefnum>
<TotalNetWeightVolume>
<Weight>
<WeightValue>18.9</WeightValue>
<WeightUOMGid>
<Gid>
<Xid>KG</Xid>
</Gid>
</WeightUOMGid>
</Weight>
<Volume>
<VolumeValue>0</VolumeValue>
<VolumeUOMGid>
<Gid>
<Xid>CR</Xid>
</Gid>
</VolumeUOMGid>
</Volume>
</TotalNetWeightVolume>
</TransOrderHeader>
</TransOrder>
</Shipment>
</ActualShipment>
</GLogXMLElement>
</TransmissionBody>
</Transmission>
</ServiceContent>
</Document>
</B2BGatewayDoc>
私が得る出力
<?xml version='1.0' ?>
<B2BGatewayDoc>
<Document>
<ServiceHeader>
<Protocol name="ANSIX12">
<Sender>941714834TEST</Sender>
<Receiver>003897733SAPT</Receiver>
<MsgType>3A4MG2</MsgType>
<ReferenceNumber/>
<PipVersion>V02.02</PipVersion>
<InstanceIdentifier/>
</Protocol>
</ServiceHeader>
<ServiceContent>
<Transmission>
<TransmissionBody>
<ReceiverSystem>
<ReceiverSystemName>XXXXX</ReceiverSystemName>
<ReceiverSystemName>YYYYY</ReceiverSystemName>
</ReceiverSystem>
<GLogXMLElement>
<ActualShipment xmlns="">
<Shipment/>
</ActualShipment>
</GLogXMLElement>
</TransmissionBody>
</Transmission>
</ServiceContent>
</Document>
</B2BGatewayDoc>
ソース値は使用可能ですが、属性xmlns
に値が割り当てられていません。タグ内のすべてのノードとタグShipment
は作成されません。
理由へのポインタは高く評価されます。