我在XSL下面使用来解析示例输入消息。 下面我给出了示例xsl和xml以及错误消息。
请告诉我这是什么问题?
请找到以下XSLT代码和输入文件(XML)....
XSLT代码
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.openapplications.org/oagis/9"
xmlns:fn="http://www.logiasoftware.fi/LGW/functions"
xmlns:tns="http://www.logiasoftware.fi/message/Transportation/2011/01"
xmlns:cdm2="http://www.logiasoftware.fi/schema/Transportation/2011/01"
xmlns:date="java.util.Date"
xmlns:comm="http://www.logiasoftware.fi/schema/Common/2011/01" xmlns:FI="urn:tieke:names:tc:ubl:Fi-TransportOrder:1:0"
xmlns:fi-cac="urn:tieke:names:tc:ubl:Fi-CAC-Tieke:1:0" xmlns:cur="urn:oasis:names:tc:ubl:codelist:CurrencyCode:1:0"
xmlns:ccts="urn:oasis:names:tc:ubl:CoreComponentParameters:1:0" xmlns:cbc="urn:oasis:names:tc:ubl:CommonBasicComponents:1:0" xmlns:cac="urn:oasis:names:tc:ubl:CommonAggregateComponents:1:0"
exclude-result-prefixes="fn" xmlns:my="functions" xmlns:ex="http://exslt.org/dates-and-times" extension-element-prefixes="ex">
<xsl:output encoding="UTF-8" method="xml" indent="yes"/>
<xsl:variable name="Guid" select="concat(Waybill/WaybillID, '_', my:CleanDateTime(current-dateTime()))"/>
<xsl:template match="Waybill" mode="transform">
<tns:ShipmentInformationMessage>
<tns:TestIndicator>
<xsl:choose>
<xsl:when test="contains(upper-case(WaybillID), 'TEST')">
<xsl:value-of select="true()"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="false()"/>
</xsl:otherwise>
</xsl:choose>
</tns:TestIndicator>
<tns:Action>
<xsl:text>new</xsl:text>
</tns:Action>
<tns:Shipments>
<tns:Shipment>
<cdm2:MasterSystemId>
<xsl:text>ETRABookingInbound</xsl:text>
</cdm2:MasterSystemId>
<cdm2:OwnerId>
<xsl:value-of select="ConsignorParty/cac:PartyIdentification/cac:ID"/>
</cdm2:OwnerId>
<cdm2:TrackingCode>
<xsl:value-of select="WaybillID"/>
</cdm2:TrackingCode>
<cdm2:DatesAndTimes>
<cdm2:ShipmentDateTime>
<xsl:choose>
<xsl:when test="cbc:IssueDate != ''">
<xsl:value-of select="my:ConvertDateTimeToCDM2(cbc:IssueDate)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ex:date-time()"/>
</xsl:otherwise>
</xsl:choose>
</cdm2:ShipmentDateTime>
</cdm2:DatesAndTimes>
</tns:Shipment>
</tns:Shipments>
</tns:ShipmentInformationMessage>
</xsl:template>
</xsl:stylesheet>
输入XML文件
<?xml version="1.0" encoding="UTF-8"?>
<Waybill xmlns="urn:tieke:names:tc:ubl:Fi-TransportOrder:1:0" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:udt="urn:oasis:names:tc:ubl:UnspecializedDatatypes:1:0" xmlns:sdt="urn:oasis:names:tc:ubl:SpecializedDatatypes:1:0"
xmlns:res="urn:oasis:names:tc:ubl:codelist:AcknowledgementResponseCode:1:0" xmlns:fi-cac="urn:tieke:names:tc:ubl:Fi-CAC-Tieke:1:0" xmlns:cur="urn:oasis:names:tc:ubl:codelist:CurrencyCode:1:0"
xmlns:ccts="urn:oasis:names:tc:ubl:CoreComponentParameters:1:0" xmlns:cbc="urn:oasis:names:tc:ubl:CommonBasicComponents:1:0" xmlns:cac="urn:oasis:names:tc:ubl:CommonAggregateComponents:1:0">
<WaybillID>300102</WaybillID>
<WaybillType>700</WaybillType>
<cbc:IssueDate>2014-02-21</cbc:IssueDate>
<cbc:Note>9</cbc:Note>
<TotalTransportHandlingUnitsQuantity quantityUnitCode="kpl">3</TotalTransportHandlingUnitsQuantity>
<cbc:GrossWeightMeasure measureUnitCode="kg">41.3</cbc:GrossWeightMeasure>
<cbc:GrossVolumeMeasure measureUnitCode="m3">.35</cbc:GrossVolumeMeasure>
<AdditionalDocumentReference>
<cac:ID>539</cac:ID>
</AdditionalDocumentReference>
<ConsignorParty>
<cac:PartyIdentification>
<cac:ID>003701078010</cac:ID>
</cac:PartyIdentification>
</ConsigneeParty>
</Waybill>
输出(错误)
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rpc="http://www.sonicsw.com/sonicxq/rpc" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope">
<SOAP-ENV:Body>
<xq:rejectedMessageInfo xmlns:xq="http://www.sonicsw.com/sonicxq">
<rejectedCode>XQ_SERVICE_EXCEPTION</rejectedCode>
<rejectedLocation container="cntFreight_ETRA" host="tntmqdit" process="ETRABookingInbound" serviceApplication="freight.ETRABookingInbound.Transform2" step="ETRAToTMSSystem" topLevelProcess="ETRABookingInbound"/>
<rejectedDetails>com.sonicsw.xq.XQServiceException: Failed to transform XQMessage part, index=0 (Error reported by XML parser; Line#: 4; Column#: 200 cvc-elt.1: Cannot find the declaration of element 'Waybill'.) (Error reported by XML parser; Line#: 4; Column#: 200 cvc-elt.1: Cannot find the declaration of element 'Waybill'.)
at com.sonicsw.xq.service.common.SAXEngine.runTransform(SAXEngine.java:470)
at com.sonicsw.xq.service.common.SAXEngine.xform(SAXEngine.java:339)
at com.sonicsw.xq.service.xform.Xformer.apply(Xformer.java:521)
at com.sonicsw.xq.service.xform.Xformer.processMessage(Xformer.java:393)
at com.sonicsw.xq.service.xform.Xformer.processRules(Xformer.java:234)
</rejectedDetails>
</xq:rejectedMessageInfo> </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
答案 0 :(得分:0)
之前我没有使用过您特定的XML / XSL框架,但是查看输出,错误是说&#34;无法找到元素的声明&#39; Waybill&#39;&#34;&#34;
查看XML,该元素具有默认命名空间:
<Waybill xmlns="urn:tieke:names:tc:ubl:Fi-TransportOrder:1:0" />
XSLT声明命名空间,但不在模板匹配元素中使用它:
<xsl:stylesheet ...
xmlns:FI="urn:tieke:names:tc:ubl:Fi-TransportOrder:1:0"
... >
<xsl:template match="Waybill" mode="transform">
...
</xsl:template>
</xsl:stylesheet>
如果您在匹配中使用命名空间,该错误是否会消失?
<xsl:template match="FI:Waybill" mode="transform">
...
</xsl:template>
通常,XML中使用的命名空间应与XPath语句中使用的命名空间相匹配 - 除非您专门编写XPath以说明&#34;匹配元素名称并忽略命名空间&#34;。