使用XSLT解析XML时如何处理十进制?

时间:2019-04-16 07:42:46

标签: java xml xslt xml-parsing xslt-1.0

我在零售部门工作,我们有 MaxLineStatus ,它暗示着客户所下订单的当前状态。 作为此过程的一部分,我需要将XML传递给XSLT进行转换。 我的XSLT检查了MaxLineStatus <3700.7777,并且在输入xml中将MaxLineStatus的值作为3200.200.100传递。 在理想情况下, 3200.200.100 小于 3700.7777 ,作为回报,它应满足条件并填充orderLine节点。

每当我通过3200.200代替xml中的3200.200.100时,我都会得到所需的输出。 我什至尝试将xslt值存储在某个变量中,然后比较该值,但仍然无法正常工作。

我正在比较下面这段代码中的值:

<xsl:attribute name="OrderLineCount"><xsl:value-of select="count(./OrderLine[(@MaxLineStatus &lt; 3700.7777) and (@MaxLineStatus!='3200.150') and (@MaxLineStatus!='1400')])" /></xsl:attribute>

谢谢,谢谢您的帮助,并以这种方式发布xml和xslt。我面临着缩进相同的问题。请原谅。

XML:

<OrderRelease APIName="sendReleaseModificationUpdateToILS" CarrierServiceCode="" DeliveryMethod="DEL" DocumentType="0003" EnterpriseCode="RETAIL" MFLocationId="70" NotificationType=" " OrderDate="20190410T06:49:07" OrderHeaderKey="2019041006490764562203" OrderLineCount="1" PriorityCode="" PriorityNumber="0" ProNumber="" ReleaseNo="1" RewardZoneIndicator="N" SCAC="" SalesOrderNo="1119100622586" ShipNode="BBY_9034" ShippingType="" WorkOrderKey="2019041006493464562225"><Shipnode Localecode="en_US_CST" NodeType="DDC" ReceiptProcessingTime="60.00" ShipNode="BBY_9034"><Extn FulfilmentDateBufferTime="0" LocationID="9034" MFLocationId="70" MobileSAS="N" /></Shipnode><Order CarrierServiceCode="" CustomerEMailID="RACHAKONDA.SATYASRINIVAS@BESTBUY.COM" DocumentType="0001" DraftOrderFlag="N" EnterpriseCode="RETAIL" MaxOrderStatus="3200.200.100" MinOrderStatus="1100.100" NotificationType=" " OrderDate="20190410T06:49:07" OrderHeaderKey="2019041006490764562203" OrderNo="1119100622586" OrderPurpose="" PriorityCode="" PriorityNumber="0" ReturnOrderHeaderKeyForExchange=" " SCAC="" SellerOrganizationCode="BBY_281" ShipNode=" " Status="Partially Awaiting Pickup Date" isHistory="N" /><OrderLine CarrierServiceCode="" ConditionVariable1="" ConditionVariable2="" DeliveryMethod="DEL" DependentOnLineKey=" " DerivedFromOrderHeaderKey="2018012921180556404483" DerivedFromOrderLineKey="2018012921180556404485" FulfillmentType="DELIVERY" HasDerivedChild="" LineType="RETURN" MaxLineStatus="3200.200.100" MaxLineStatusDesc="Awaiting Pickup Date" MinLineStatus="3200.200.100" MinLineStatusDesc="Awaiting Pickup Date" OpenQty="1" OrderLineKey="2019041006490764562204" OrderedQty="1" PrimeLineNo="1" ProcureFromNode="" PromisedApptEndDate="20190413T19:00:00" PromisedApptStartDate="20190413T07:00:00" SCAC="" ShipNode="BBY_9034" ShipToKey=" " Status="Awaiting Pickup Date" SubLineNo="1"><Extn ExpectedShipDate="20190410T00:00:00" StreetDate="19000101T00:00:00"><EOMSOrderLineList><EOMSOrderLine ExpectedApptEndDate="20190413T19:00:00" ExpectedApptStartDate="20190413T07:00:00" HingeSettings="" LineShipNodeWMS="WMS" OrderLineKey="2019041006490764562204" SellingStoreId="281" /></EOMSOrderLineList></Extn><Item CustomerItem="3519796" CustomerItemDesc="NINTENDO DS UNIVERSAL GAME SELECTOR CASE" ItemID="1640461" ManufacturerItem="52LB5D" ProductClass="" ProductLine="9.99.224" UnitOfMeasure="EACH" /><Notes NumberOfNotes="0" /><ParentOrderLineRelationships /></OrderLine></OrderRelease>

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" indent="yes" /><xsl:template match="/OrderRelease"><xsl:copy><xsl:copy-of select="@*" /><xsl:attribute name="MFLocationId"><xsl:value-of select="./Shipnode/Extn/@MFLocationId" /></xsl:attribute><Extn><xsl:attribute name="ReleaseSeqNo"><xsl:value-of select="./Extn/@ReleaseSeqNo" /></xsl:attribute></Extn><xsl:attribute name="OrderLineCount"><xsl:value-of select="count(./OrderLine[(@MaxLineStatus &lt; 3700.7777) and (@MaxLineStatus!='3200.150') and (@MaxLineStatus!='1400')])" /></xsl:attribute><xsl:for-each select="./OrderLine[(@MaxLineStatus &lt; 3700.7777) and (@MaxLineStatus!='3200.150') and (@MaxLineStatus!='1400')]"><OrderLine><xsl:copy-of select="./@*" /><xsl:copy-of select="./OrderLineInvAttRequest" /><Item><xsl:copy-of select="./Item/@*" /><Extn><xsl:attribute name="BrandItemID"><xsl:value-of select="./Item/@CustomerItem" /></xsl:attribute></Extn></Item><Notes><xsl:copy-of select="./Notes/*" /></Notes><ParentOrderLineRelationships><xsl:copy-of select="./ParentOrderLineRelationships/*" /></ParentOrderLineRelationships><Extn><xsl:copy-of select="./Extn/*" /></Extn></OrderLine></xsl:for-each><Notes><xsl:for-each select="./Notes/Note"><xsl:copy-of select="current()" /></xsl:for-each></Notes><Order><xsl:attribute name="OrderPurpose"><xsl:value-of select="./Order/@OrderPurpose" /></xsl:attribute><xsl:attribute name="ReturnOrderHeaderKeyForExchange"><xsl:value-of select="./Order/@ReturnOrderHeaderKeyForExchange" /></xsl:attribute><xsl:attribute name="CustomerEMailID"><xsl:value-of select="./Order/@CustomerEMailID" /></xsl:attribute><xsl:attribute name="SellerOrganizationCode"><xsl:value-of select="./Order/@SellerOrganizationCode" /></xsl:attribute><Extn><xsl:attribute name="BillingPhoneNo"><xsl:value-of select="./Order/Extn/@BillingPhoneNo" /></xsl:attribute></Extn></Order><xsl:copy-of select="./PersonInfoShipTo" /></xsl:copy></xsl:template>

实际结果:

<OrderRelease APIName="sendReleaseModificationUpdateToILS" CarrierServiceCode="" DeliveryMethod="DEL" DocumentType="0003" EnterpriseCode="RETAIL" MFLocationId="70" NotificationType=" " OrderDate="20190410T06:49:07" OrderHeaderKey="2019041006490764562203" OrderLineCount="1" PriorityCode="" PriorityNumber="0" ProNumber="" ReleaseNo="1" RewardZoneIndicator="N" SCAC="" SalesOrderNo="1119100622586" ShipNode="BBY_9034" ShippingType="" WorkOrderKey="2019041006493464562225"><Extn ReleaseSeqNo="" /><Notes></Notes><Order OrderPurpose="" ReturnOrderHeaderKeyForExchange=" " CustomerEMailID="RACHAKONDA.SATYASRINIVAS@BESTBUY.COM" SellerOrganizationCode="BBY_281"><Extn BillingPhoneNo="" /></Order></OrderRelease>

预期结果:

<OrderRelease APIName="sendReleaseModificationUpdateToILS" CarrierServiceCode="" DeliveryMethod="DEL" DocumentType="0003" EnterpriseCode="RETAIL" MFLocationId="70" NotificationType=" " OrderDate="20190410T06:49:07" OrderHeaderKey="2019041006490764562203" OrderLineCount="1" PriorityCode="" PriorityNumber="0" ProNumber="" ReleaseNo="1" RewardZoneIndicator="N" SCAC="" SalesOrderNo="1119100622586" ShipNode="BBY_9034" ShippingType="" WorkOrderKey="2019041006493464562225"><Extn ReleaseSeqNo="" /><OrderLine CarrierServiceCode="" ConditionVariable1="" ConditionVariable2="" DeliveryMethod="DEL" DependentOnLineKey=" " DerivedFromOrderHeaderKey="2018012921180556404483" DerivedFromOrderLineKey="2018012921180556404485" FulfillmentType="DELIVERY" HasDerivedChild="" LineType="RETURN" MaxLineStatus="3200.200.100" MaxLineStatusDesc="Awaiting Pickup Date" MinLineStatus="3200.200.100" MinLineStatusDesc="Awaiting Pickup Date" OpenQty="1" OrderLineKey="2019041006490764562204" OrderedQty="1" PrimeLineNo="1" ProcureFromNode="" PromisedApptEndDate="20190413T19:00:00" PromisedApptStartDate="20190413T07:00:00" SCAC="" ShipNode="BBY_9034" ShipToKey=" " Status="Awaiting Pickup Date" SubLineNo="1"><Item CustomerItem="3519796" CustomerItemDesc="NINTENDO DS UNIVERSAL GAME SELECTOR CASE" ItemID="1640461" ManufacturerItem="52LB5D" ProductClass="" ProductLine="9.99.224" UnitOfMeasure="EACH"><Extn BrandItemID="3519796" /></Item><Notes></Notes><ParentOrderLineRelationships></ParentOrderLineRelationships><Extn><EOMSOrderLineList><EOMSOrderLine ExpectedApptEndDate="20190413T19:00:00" ExpectedApptStartDate="20190413T07:00:00" HingeSettings="" LineShipNodeWMS="WMS" OrderLineKey="2019041006490764562204" SellingStoreId="281" /></EOMSOrderLineList></Extn></OrderLine><Notes></Notes><Order OrderPurpose="" ReturnOrderHeaderKeyForExchange=" " CustomerEMailID="RACHAKONDA.SATYASRINIVAS@BESTBUY.COM" SellerOrganizationCode="BBY_281"><Extn BillingPhoneNo="" /></Order></OrderRelease>

1 个答案:

答案 0 :(得分:1)

在XSLT 1.0中,比较<>关系的字符串的唯一方法是排序。 <>运算符始终会转换为数字(如果无法将值转换为数字,则将其视为NaN)。

理想情况下,请升级到XSLT的最新版本(1.0的版本已经非常老)。

如果您不能这样做,那将是一个复杂的解决方法。三种可能的方法:

(a)找到某种方法将这些“点分十进制”值转换为正确排序的数字。 (例如,将每个组件填充到标准位数,然后去除点)。

(b)通过查看序列号对值进行排序,分配序列号并测试值是否满足相关条件。

(c)用Java之类的外部语言调用扩展功能进行比较。