Как проверить два значения, чтобы увидеть, отличаются ли они? -> Относится к узлам Item.DeliveryDate
и Item.OrigDeliveryDate
.
Если да, новый узел LineChangeDeliveryDate
должен быть создан со значением yes
, в противном случае со значением no
.
XML на данный момент:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<OrderResponse>
<Interchange>
<Interchange_Control_Number>5637248870</Interchange_Control_Number>
</Interchange>
<HeaderInformation>
<ConfirmDocNum>SO0009783-1</ConfirmDocNum>
<TransportDetails>
<DeliveryMode>ROU</DeliveryMode>
</TransportDetails>
</HeaderInformation>
<LineInformation>
<Item>
<DeliveryDate>2020-01-27</DeliveryDate>
<OrigDeliveryDate>2019-12-07</OrigDeliveryDate>
</Item>
</LineInformation>
</OrderResponse>
XML новый / правильный:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<OrderResponse>
<Interchange>
<Interchange_Control_Number>5637248870</Interchange_Control_Number>
</Interchange>
<HeaderInformation>
<ConfirmDocNum>SO0009783-1</ConfirmDocNum>
<TransportDetails>
<DeliveryMode>ROU</DeliveryMode>
</TransportDetails>
</HeaderInformation>
<LineInformation>
<Item>
<DeliveryDate>2020-01-27</DeliveryDate>
<OrigDeliveryDate>2019-12-07</OrigDeliveryDate>
<LineChangeDeliveryDate>yes</LineChangeDeliveryDate>
</Item>
</LineInformation>
</OrderResponse>
Текущий XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:key name="header_text" match="HeaderText" use="Text"/>
<xsl:key name="line_text" match="LineText" use="concat(../LineNum, '|', Text)"/>
<xsl:key name="allowance_charge_header" match="AllowanceOrCharge_Header" use="concat(Code, '|', Amount)"/>
<xsl:key name="allowance_charge_line" match="AllowanceOrCharge_Line" use="concat(../LineNum, '|', Code, '|', Amount)"/>
<xsl:key use="concat(../LineNum, '|', Text)" match="LineText" name="line_text"/>
<!-- Identity-Template für die nicht explizit benannten Elemente -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="HeaderText[generate-id() != generate-id(key('header_text', Text)[1])]" />
<xsl:template match="LineText[generate-id() != generate-id(key('line_text', concat(../LineNum, '|', Text))[1])]" />
<xsl:template match="AllowanceOrCharge_Header[generate-id() != generate-id(key('allowance_charge_header', concat(Code, '|', Amount))[1])]" />
<xsl:template match="AllowanceOrCharge_Line[generate-id() != generate-id(key('allowance_charge_line', concat(../LineNum, '|', Code, '|', Amount))[1])]" />
<xsl:template match="LineText[generate-id() != generate-id(key('line_text', concat(../LineNum, '|', Text))[1])]"/>
<xsl:template match="Item">
<xsl:copy>
<LineChangeDeliveryDate>
<xsl:choose>
<xsl:when test="OrigDeliveryDate = DeliveryDate"/>
<xsl:value-of select="'yes'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'no'"/>
</xsl:otherwise>
</xsl:choose>
</LineChangeDeliveryDate>
<!--copy all other nodes-->
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- delete empty nodes -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/>
</xsl:stylesheet>