Why my XSLT (from Schematron) Does not validate my xml file ?

808 Views Asked by At

I am trying to validate an XML file. I have created a simple Schematron (.sch) file, and converted it into XSLT file (using oxygen). Also in oxygen all validation works as expected. However i have a custom service written in JAVA (quite complicated) that deals with the transformations. (i know that the service works as i have been using it for a while with many other xml->xslt files). However what keeps me curious, is why the XSLT generated by Oxygen does not work ( or maybe it does i just dont know ). Normally when xml-transformation service processes XSLT file (and it fails) it throws an error. In this case it doesn't throw an error, and my XML file just dissapears ?. I.E if i change one of the values in XSLT file so the message should fail on purpose, the service still does not throw an error ?. And the questions is how do i know when the transformation failed when using this XSLT file ? can i print something such as "Validation failed" or something ?

This is my XSLT generated by Oxygen

<?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>

And this is the XML file i am trying to validate

<?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>
0

There are 0 best solutions below