我正在尝试验证XML文件。我创建了一个简单的Schematron(.sch)文件,并将其转换为XSLT文件(使用氧气)。同样在氧气中,所有验证都按预期工作。但是我有一个用JAVA编写的自定义服务(非常复杂)来处理转换。 (我知道该服务可以工作,因为我已经使用了许多其他xml-> xslt文件)。然而让我好奇的是,为什么由Oxygen生成的XSLT不起作用(或者它可能我不知道)。通常,当xml-transformation服务处理XSLT文件(并且它失败)时,它会抛出错误。在这种情况下,它不会抛出错误,我的XML文件只是消失了? I.E如果我更改了XSLT文件中的一个值,那么消息应该故意失败,服务仍然不会抛出错误?问题是如何在使用此XSLT文件时知道转换何时失败?我可以打印诸如“验证失败”之类的东西吗?
这是我的Oxygen生成的XSLT
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<axsl:stylesheet xmlns:axsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sch="http://www.ascc.net/xml/schematron" xmlns:exsl="http://exslt.org/common" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
<axsl:output method="text"/>
<axsl:template match="*|@*" mode="schematron-get-full-path">
<axsl:apply-templates select="parent::*" mode="schematron-get-full-path"/>
<axsl:text>/</axsl:text>
<axsl:if test="count(. | ../@*) = count(../@*)">@</axsl:if>
<axsl:value-of select="name()"/>
<axsl:text>[</axsl:text>
<axsl:value-of select="1+count(preceding-sibling::*[name()=name(current())])"/>
<axsl:text>]</axsl:text>
</axsl:template>
<axsl:template match="/">
<axsl:apply-templates select="/" mode="M0"/>
</axsl:template>
<axsl:template match="EnvelopeHeader" priority="102" mode="M0">
<axsl:choose>
<axsl:when test="SourcePartnerID = 'UK00000010888'"/>
<axsl:otherwise>
<axsl:message>Source partner id should be UK0000001088<axsl:text> (</axsl:text>SourcePartnerID = 'UK0000001088'<axsl:text>)</axsl:text>
<axsl:text> [</axsl:text>assert<axsl:text>]</axsl:text>
</axsl:message>
</axsl:otherwise>
</axsl:choose>
<axsl:choose>
<axsl:when test="DestinationDivisionID = '9725652'"/>
<axsl:otherwise>
<axsl:message>DestinationDivision id should be 9725652<axsl:text> (</axsl:text>DestinationDivisionID = '9725652'<axsl:text>)</axsl:text>
<axsl:text> [</axsl:text>assert<axsl:text>]</axsl:text>
</axsl:message>
</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M0"/>
</axsl:template>
<axsl:template match="FinancialDocument/DocumentHeader/Organisation[@Type = 'Buyer']" priority="101" mode="M0">
<axsl:choose>
<axsl:when test="Name = 'AngliaFarmersLtd'"/>
<axsl:otherwise>
<axsl:message>Buyer name must be AngliaFarmersLtd<axsl:text> (</axsl:text>Name = 'AngliaFarmersLtd'<axsl:text>)</axsl:text>
<axsl:text> [</axsl:text>assert<axsl:text>]</axsl:text>
</axsl:message>
</axsl:otherwise>
</axsl:choose>
<axsl:choose>
<axsl:when test="Section/Location/Address/PostalCode = 'NR9 5BZ'"/>
<axsl:otherwise>
<axsl:message>Buyer post code must be NR9 5BZ<axsl:text> (</axsl:text>Section/Location/Address/PostalCode = 'NR9 5BZ'<axsl:text>)</axsl:text>
<axsl:text> [</axsl:text>assert<axsl:text>]</axsl:text>
</axsl:message>
</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M0"/>
</axsl:template>
<axsl:template match="text()" priority="-1" mode="M0"/>
<axsl:template match="text()" priority="-1"/>
</axsl:stylesheet>
这是我试图验证的XML文件
<?xml version="1.0" encoding="iso-8859-1"?>
<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://mappings.f4f.com/F4FXML/Schemas/v5/financial.xsd">
<EnvelopeHeader>
<SchemaVersion>5.1</SchemaVersion>
<EnvelopeCreated>20140108</EnvelopeCreated>
<EnvelopeTrackingID>1746978</EnvelopeTrackingID>
<EnvelopeRevisionNumber>1</EnvelopeRevisionNumber>
<SourcePartnerID>UK0000001088</SourcePartnerID>
<SourceDivisionID>UK0000001088</SourceDivisionID>
<DestinationPartnerID>ang</DestinationPartnerID>
<DestinationDivisionID>9725652</DestinationDivisionID>
<TestIndicator>True</TestIndicator>
</EnvelopeHeader>
<FinancialDocument MessageLifecycle="New" DocumentSequenceNumber="1" FinancialDocumentType="Tax Invoice">
<DocumentHeader Language="EN" Currency="GBP">
<DocumentReference Type="Invoice Number" AssignedBy="Supplier">1746978</DocumentReference>
<DocumentReference Type="Delivery Note Number" AssignedBy="Supplier">1746978</DocumentReference>
<DocumentReference Type="Purchase Order Number" AssignedBy="Buyer">1759902</DocumentReference>
<DocumentDate Type="Document Created">20131216</DocumentDate>
<DocumentDate Type="Invoice Date">20131219</DocumentDate>
<Organisation Type="Buyer">
<Reference Type="Organisation ID" AssignedBy="F4F">ang</Reference>
<Reference Type="Organisation ID" AssignedBy="Supplier">9501042</Reference>
<Name>AngliaFarmersLtd</Name>
<Section BusinessTransactionRole="Bill To Party">
<Reference Type="Organisation ID" AssignedBy="Supplier">9501042</Reference>
<Location Type="Section Address">
<Address>
<Name>AngliaFarmersLtd</Name>
<StreetAddress>HoninghamThorpe</StreetAddress>
<StreetAddress>Colton</StreetAddress>
<CityName>Norwich</CityName>
<CountyDistrictName>Norfolk</CountyDistrictName>
<PostalCode>NR9 5BZ</PostalCode>
<CountryCode>GB</CountryCode>
</Address>
</Location>
</Section>
<Section BusinessTransactionRole="Sold To Party">
<Reference Type="Organisation ID" AssignedBy="Supplier">9501042</Reference>
<Location Type="Section Address">
<Address>
<Name>AngliaFarmersLtd</Name>
<StreetAddress>HoninghamThorpe</StreetAddress>
<StreetAddress>Colton</StreetAddress>
<CityName>Norwich</CityName>
<CountyDistrictName>Norfolk</CountyDistrictName>
<PostalCode>NR9 5BZ</PostalCode>
<CountryCode>GB</CountryCode>
</Address>
</Location>
</Section>
</Organisation>
<Organisation Type="Supplier">
<Reference Type="Organisation ID" AssignedBy="F4F">UK0000001088</Reference>
<Reference Type="Organisation ID" AssignedBy="Buyer">T00028</Reference>
<Reference Type="VAT Registration Number" AssignedBy="Government Agency">GB844283419</Reference>
<Reference Type="Company Registered Number" AssignedBy="Government Agency">04168225</Reference>
<Reference Type="Virtual Location Code" AssignedBy="Supplier">http://www.gb-oils.co.uk</Reference>
<Name>Butler Fuels</Name>
<Section BusinessTransactionRole="Invoice From Party">
<Reference Type="Organisation ID" AssignedBy="F4F">UK0000001088</Reference>
<Location Type="Section Address">
<Address>
<StreetAddress>302 Bridgewater Place</StreetAddress>
<StreetAddress>Birchwood Park, Birchwood</StreetAddress>
<CityName>Warrington</CityName>
<CountyDistrictName>Cheshire</CountyDistrictName>
<PostalCode>WA3 6XG</PostalCode>
<CountryCode>GB</CountryCode>
</Address>
</Location>
</Section>
</Organisation>
<MovementDetails Phase="1" Movement="1" DeliveryCollectionIndicator="Delivery">
<Date Type="Actual Arrival Date" AssignedBy="Supplier">20131219</Date>
<Location Type="Delivery Point">
<Reference Type="Location Code" AssignedBy="Supplier">9725652</Reference>
<Address>
<Name>AngliaFarmersLtd</Name>
<StreetAddress>AlderhillLimited</StreetAddress>
<StreetAddress>HumbletoftFarm</StreetAddress>
<CityName>SandyLane</CityName>
<CountyDistrictName>Derham norfolk</CountyDistrictName>
<PostalCode>NR19 2QA</PostalCode>
<CountryCode>GB</CountryCode>
</Address>
</Location>
</MovementDetails>
<TermsAndConditions>
<PaymentTerms>
<PaymentTiming>
<PaymentRequiredBy Type="Payment Due Date">20140128</PaymentRequiredBy>
</PaymentTiming>
<PaymentMethod>Previously Agreed</PaymentMethod>
</PaymentTerms>
</TermsAndConditions>
</DocumentHeader>
<DocumentLine LineStatus="New" LineNumber="1">
<LineDate Type="Shipment Note Date" AssignedBy="Supplier">20131219</LineDate>
<LineComponent>
<Product>
<Specification>
<Reference Type="Identifier" AssignedBy="Supplier">004</Reference>
<Description Type="Name" AssignedBy="Supplier">Gasoil (Class A2)</Description>
</Specification>
<Quantity Type="Invoiced" AssignedBy="Supplier" UnitOfMeasure="Litre">1000.00</Quantity>
<Price UOM="Litre">
<ActualUnitPrice>0.6634</ActualUnitPrice>
</Price>
</Product>
<ValueBeforeTax>663.40</ValueBeforeTax>
<Tax TaxRate="5.00" TaxCode="R" InternalTaxCode="R">33.17</Tax>
<ValueAfterTax>696.57</ValueAfterTax>
</LineComponent>
</DocumentLine>
<DocumentTrailer>
<TaxTrailer TaxCode="R" TaxRate="5.00">
<TotalValueBeforeTax>663.40</TotalValueBeforeTax>
<TotalTax>33.17</TotalTax>
<TotalValueAfterTax>696.57</TotalValueAfterTax>
</TaxTrailer>
<Totals TotalType="Control">
<TotalLineCount>1</TotalLineCount>
<TotalValueBeforeTax>663.40</TotalValueBeforeTax>
<TotalTax>33.17</TotalTax>
<TotalValueAfterTax>696.57</TotalValueAfterTax>
</Totals>
</DocumentTrailer>
</FinancialDocument>
<EnvelopeTrailer>
<TotalMessageCount>1</TotalMessageCount>
</EnvelopeTrailer>
</Envelope>