Я использую следующий код в моем XSL:
<xsl:if test="S_DTM/C_C507/D_2005=123">
<EstimatedArrivelDateV2><xsl:value-of select="S_DTM/C_C507/D_2380"/></EstimatedArrivelDateV2><br>
</xsl:if>
Однако есть два узла D_2005, которые будут истинны для "= 123". Каждый из них имеет различное значение в дочернем элементе (D_2380).
Я борюсь с тем, чтобы вернуть значение второго экземпляра D_2380. Я пробовал нотацию [2], но она нарушает XSL. Мне нужно сохранить как XSL v1, если это возможно.
спасибо
Ввод ниже - я хочу вернуть значение '201907141253'
<?xml version="1.0" encoding="UTF-8"?>
<hub:HubMessage
xmlns:hub="http://www.example.org/HubMessage"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/HubMessage HubMessage.xsd">
<hub:HubMessageRequest>
<hub:MessageType>D42Edifact</hub:MessageType>
<MessageRequestData>
<D42Edifact>
<S_UNB>
<C_S001>
<D_0001>UNOA</D_0001>
<D_0002>1</D_0002>
</C_S001>
<C_S002>
<D_0004>ABC</D_0004>
<D_0007>XXX</D_0007>
</C_S002>
<C_S003>
<D_0010>MOL</D_0010>
<D_0007>001</D_0007>
</C_S003>
<C_S004>
<D_0017>190604</D_0017>
<D_0019>1108</D_0019>
</C_S004>
<D_0020>7599</D_0020>
</S_UNB>
<M_IFTSTA>
<S_UNH>
<D_0062>7272</D_0062>
<C_S009>
<D_0065>IFTSTA</D_0065>
<D_0052>D</D_0052>
<D_0054>96B</D_0054>
<D_0051>UN</D_0051>
</C_S009>
</S_UNH>
<S_BGM>
<C_C002>
<D_1001>23</D_1001>
<D_1131/>
<D_3055/>
<D_1000>IFTSTA</D_1000>
</C_C002>
</S_BGM>
<S_DTM>
<C_C507>
<D_2005>137</D_2005>
<D_2380>201906071253</D_2380>
<D_2379>203</D_2379>
</C_C507>
</S_DTM>
<G_SG4>
<S_CNI>
<D_1490>1</D_1490>
</S_CNI>
<G_SG5>
<S_STS>
<C_C601>
<D_9015>1</D_9015>
<D_1131/>
<D_3055>6</D_3055>
</C_C601>
<C_C555>
<D_9011>ETAUPDT</D_9011>
</C_C555>
</S_STS>
<S_RFF>
<C_C506>
<D_1153>VT</D_1153>
<D_1154>ABCFA2AX1K1Z51338</D_1154>
<D_1156>J0744</D_1156>
</C_C506>
</S_RFF>
<S_RFF>
<C_C506>
<D_1153>VT</D_1153>
<D_1154>ABCHA2A16K1F70673</D_1154>
<D_1156>J0744</D_1156>
</C_C506>
</S_RFF>
<S_RFF>
<C_C506>
<D_1153>BL</D_1153>
<D_1154>18000650655</D_1154>
</C_C506>
</S_RFF>
<S_RFF>
<C_C506>
<D_1153>BN</D_1153>
<D_1154>18000650655</D_1154>
</C_C506>
</S_RFF>
<S_DTM>
<C_C507>
<D_2005>123</D_2005>
<D_2380>201906131253</D_2380>
<D_2379>203</D_2379>
</C_C507>
</S_DTM>
<S_NAD>
<D_3035>CA</D_3035>
<C_C082>
<D_3039>MVT</D_3039>
</C_C082>
</S_NAD>
<S_NAD>
<D_3035>CZ</D_3035>
<C_C082>
<D_3039>XYZ</D_3039>
</C_C082>
</S_NAD>
<S_LOC>
<D_3227>ZZ</D_3227>
<C_C517>
<D_3225>CNXNA</D_3225>
</C_C517>
</S_LOC>
<G_SG6>
<S_TDT>
<D_8051>S1</D_8051>
<D_8028>0166A</D_8028>
<C_C220>
<D_8067>1</D_8067>
<D_8066>9207388</D_8066>
</C_C220>
</S_TDT>
<S_LOC>
<D_3227>ZZ</D_3227>
<C_C517>
<D_3225>CNXNA</D_3225>
</C_C517>
</S_LOC>
<S_LOC>
<D_3227>PL</D_3227>
<C_C517>
<D_3225>SIKOP</D_3225>
</C_C517>
</S_LOC>
<S_LOC>
<D_3227>PD</D_3227>
<C_C517>
<D_3225>CNXNA</D_3225>
</C_C517>
</S_LOC>
<S_DTM>
<C_C507>
<D_2005>186</D_2005>
<D_2380>201906042010</D_2380>
<D_2379>203</D_2379>
</C_C507>
</S_DTM>
<S_DTM>
<C_C507>
<D_2005>123</D_2005>
<D_2380>201907141253</D_2380>
<D_2379>203</D_2379>
</C_C507>
</S_DTM>
</G_SG6>
</G_SG5>
</G_SG4>
<S_UNT>
<D_0074>19</D_0074>
<D_0062>7272</D_0062>
</S_UNT>
</M_IFTSTA>
<S_UNZ>
<D_0036>1</D_0036>
<D_0020>7599</D_0020>
</S_UNZ>
</D42Edifact>
</MessageRequestData>
</hub:HubMessageRequest>
</hub:HubMessage>
и текущий XSL выглядит следующим образом:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xs fn">
<xsl:output method="xml" encoding="UTF-8" indent="no"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="D42Edifact">
<D42Edifact>
<xsl:apply-templates select="S_UNB"/>
<xsl:apply-templates select="M_IFTSTA"/>
<xsl:apply-templates select="S_UNZ"/>
<xsl:apply-templates select="S_UNT"/>
</D42Edifact>
</xsl:template>
<xsl:template match="S_UNB">
<InterchangeHeader>
<Syntax_identifier>
<Syntax_ID><xsl:value-of select="C_S001/D_0001"/></Syntax_ID>
<Syntax_version><xsl:value-of select="C_S001/D_0002"/></Syntax_version>
</Syntax_identifier>
<Sender><xsl:value-of select="C_S003/D_0010"/></Sender>
<Recipient><xsl:value-of select="C_S002/D_0004"/></Recipient>
</InterchangeHeader>
</xsl:template>
<xsl:template match="M_IFTSTA">
<xsl:apply-templates select="G_SG4" />
</xsl:template>
<xsl:template match="G_SG4">
<SG4>
<xsl:apply-templates select="G_SG5" />
</SG4>
</xsl:template>
<xsl:template match="G_SG5">
<SG5>
<xsl:apply-templates select="S_STS"/>
<xsl:apply-templates select="S_RFF" />
<EventDateTime><xsl:value-of select="S_DTM/C_C507/D_2380"/></EventDateTime>
<xsl:apply-templates select="S_LOC"/>
<xsl:apply-templates select="G_SG6"/>
<xsl:apply-templates select="G_SG7" />
<xsl:if test="S_DTM/C_C507/D_2005=123">
<EstimatedArrivelDateV2><xsl:value-of select="S_DTM/C_C507/D_2380"/></EstimatedArrivelDateV2>
</xsl:if>
</SG5>
</xsl:template>
<xsl:template match="G_SG6">
<SG6>
<xsl:apply-templates select="S_TDT"/>
<xsl:apply-templates select="S_LOC"/>
<xsl:apply-templates select="S_DTM"/>
</SG6>
</xsl:template>
<xsl:template match="G_SG7">
<SG7>
<xsl:apply-templates select="S_EQD"/>
</SG7>
</xsl:template>
<xsl:template match="S_UNT">
<MessageTrailer>
<Segments>
<xsl:value-of select="D_0074"/>
</Segments>
<MessageID>
<xsl:value-of select="D_0062"/>
</MessageID>
</MessageTrailer>
</xsl:template>
<xsl:template match="S_UNZ">
<InterchangeTrailer>
<ControlCount>
<xsl:value-of select="D_0036"/>
</ControlCount>
<InterchangeID>
<xsl:value-of select="D_0020"/>
</InterchangeID>
</InterchangeTrailer>
</xsl:template>
<xsl:template match="S_RFF">
<xsl:if test="C_C506/D_1153='VT'">
<VehicleRecord>
<VIN><xsl:value-of select="C_C506/D_1154"/></VIN>
<DistCICode><xsl:value-of select="C_C506/D_1156"/></DistCICode>
</VehicleRecord>
</xsl:if>
<xsl:if test="C_C506/D_1153='BL'">
<BillOfLoading><xsl:value-of select="C_C506/D_1154"/></BillOfLoading>
</xsl:if>
<xsl:if test="C_C506/D_1153='BN'">
<BookingNumber><xsl:value-of select="C_C506/D_1154"/></BookingNumber>
</xsl:if>
<xsl:if test="C_C506/D_1153='EQ'">
<ContainerNumber><xsl:value-of select="C_C506/D_1154"/></ContainerNumber>
</xsl:if>
<xsl:if test="C_C506/D_1153='SR'">
<SRNumber><xsl:value-of select="C_C506/D_1154"/></SRNumber>
</xsl:if>
</xsl:template>
<xsl:template match="S_STS">
<StatusInfo>
<Status><xsl:value-of select="C_C555/D_9011"/></Status>
</StatusInfo>
</xsl:template>
<xsl:template match="S_TDT">
<Transport>
<StageQual>
<xsl:if test="D_8051='L1'">
<xsl:text>DomesticLeg</xsl:text>
</xsl:if>
<xsl:if test="D_8051='S1'">
<xsl:text>ShippingLeg</xsl:text>
</xsl:if>
<xsl:if test="D_8051='F1'">
<xsl:text>InternationalLeg</xsl:text>
</xsl:if>
</StageQual>
<Conveyance_ref_number><xsl:value-of select="D_8028"/></Conveyance_ref_number>
<Mode_of_transport>
<xsl:if test="C_C220/D_8067=1">
<xsl:text>Ocean</xsl:text>
</xsl:if>
<xsl:if test="C_C220/D_8067=2">
<xsl:text>Land</xsl:text>
</xsl:if>
</Mode_of_transport>
<VesselDetails>
<xsl:if test="C_C220/D_8067=1">
<VesselCode><xsl:value-of select="C_C220/D_8066"/></VesselCode>
<VesselName></VesselName>
<VesselFlag></VesselFlag>
</xsl:if>
</VesselDetails>
</Transport>
</xsl:template>
<xsl:template match="S_LOC">
<xsl:if test="D_3227='ZZ'">
<EventLocation><xsl:value-of select="C_C517/D_3225"/></EventLocation>
</xsl:if>
<xsl:if test="D_3227='PR'">
<PlaceOfDelivery><xsl:value-of select="C_C517/D_3225"/></PlaceOfDelivery>
</xsl:if>
<xsl:if test="D_3227='PL'">
<PlaceOfLoading><xsl:value-of select="C_C517/D_3225"/></PlaceOfLoading>
</xsl:if>
<xsl:if test="D_3227='PD'">
<PlaceOfDischarge><xsl:value-of select="C_C517/D_3225"/></PlaceOfDischarge>
</xsl:if>
<xsl:if test="D_3227='PR'">
<PlaceOfReceipt><xsl:value-of select="C_C517/D_3225"/></PlaceOfReceipt>
</xsl:if>
</xsl:template>
<xsl:template match="S_DTM">
<xsl:if test="C_C507/D_2005=35">
<ActualDeliveryDate><xsl:value-of select="C_C507/D_2380"/></ActualDeliveryDate>
</xsl:if>
<xsl:if test="C_C507/D_2005=123">
<EstimatedArrivelDate><xsl:value-of select="C_C507/D_2380"/></EstimatedArrivelDate>
</xsl:if>
<xsl:if test="C_C507/D_2005=178">
<ActualArrivalDate><xsl:value-of select="C_C507/D_2380"/></ActualArrivalDate>
</xsl:if>
<xsl:if test="C_C507/D_2005=186">
<ActualDepartureDate><xsl:value-of select="C_C507/D_2380"/></ActualDepartureDate>
</xsl:if>
<xsl:if test="C_C507/D_2005=196">
<EarliestDepartureDate><xsl:value-of select="C_C507/D_2380"/></EarliestDepartureDate>
</xsl:if>
<xsl:if test="C_C507/D_2005=231">
<EarliestArrivalDate><xsl:value-of select="C_C507/D_2380"/></EarliestArrivalDate>
</xsl:if>
<xsl:if test="C_C507/D_2005=334">
<StatusChangeDate><xsl:value-of select="C_C507/D_2380"/></StatusChangeDate>
</xsl:if>
</xsl:template>
<xsl:template match="S_EQD">
<EquipmentDetails>
<Type>
<xsl:if test="D_8053='CN'">
<xsl:text>Container</xsl:text>
</xsl:if>
<xsl:if test="D_8053='TP'">
<xsl:text>Transporter</xsl:text>
</xsl:if>
</Type>
<ID><xsl:value-of select="C_C237/D_8260"/></ID>
</EquipmentDetails>
</xsl:template>
</xsl:stylesheet>