0

i have been trying to validate xml through xslt for couple of hours. i have following xsl form for xml validation. every time i try to validate xml, i get following warnings below and empty currencyid attributes in xml are ignored and xml validate although its not. Does anyone has an idea why its ignored and validated ?

  <xsl:variable name="CurrencyCodeList"
             select="',AED,AFN,ALL,AMD,ANG,AOA,ARS,AUD,AWG,AZN,BAM,BBD,BDT,BGN,BHD,BIF,BMD,BND,BOB,BOV,BRL,BSD,BTN,BWP,BYR,BZD,CAD,CDF,CHE,CHF,CHW,CLF,CLP,CNY,COP,COU,CRC,CUC,CUP,CVE,CZK,DJF,DKK,DOP,DZD,EEK,EGP,ERN,ETB,EUR,FJD,FKP,GBP,GEL,GHS,GIP,GMD,GNF,GTQ,GWP,GYD,HKD,HNL,HRK,HTG,HUF,IDR,ILS,INR,IQD,IRR,ISK,JMD,JOD,JPY,KES,KGS,KHR,KMF,KPW,KRW,KWD,KYD,KZT,LAK,LBP,LKR,LRD,LSL,LTL,LVL,LYD,MAD,MAD,MDL,MGA,MKD,MMK,MNT,MOP,MRO,MUR,MVR,MWK,MXN,MXV,MYR,MZN,NAD,NGN,NIO,NOK,NPR,NZD,OMR,PAB,PEN,PGK,PHP,PKR,PLN,PYG,QAR,RON,RSD,RUB,RWF,SAR,SBD,SCR,SDG,SEK,SGD,SHP,SLL,SOS,SRD,STD,SVC,SYP,SZL,THB,TJS,TMT,TND,TOP,TRY,TTD,TWD,TZS,UAH,UGX,USD,USN,USS,UYI,UYU,UZS,VEF,VND,VUV,WST,XAF,XAG,XAU,XBA,XBB,XBC,XBD,XCD,XDR,XFU,XOF,XPD,XPF,XPF,XPF,XPT,XTS,XXX,YER,ZAR,ZMK,ZWL,'"/>


<xsl:template match="//@currencyID" priority="1008" mode="M0">
      <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl" context="//@currencyID"/>

        <!--ASSERT -->
  <xsl:choose>
     <xsl:when test="contains($CurrencyCodeList, concat(',',.,','))"/>
     <xsl:otherwise>
        <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
                            test="contains($CurrencyCodeList, concat(',',.,','))">
           <xsl:attribute name="location">
              <xsl:apply-templates select="." mode="schematron-select-full-path"/>
           </xsl:attribute>
           <svrl:text>Geçersiz currencyID niteliği : '<xsl:text/>
              <xsl:value-of select="."/>
              <xsl:text/>'. Geçerli değerler için kod listesine bakınız.</svrl:text>
        </svrl:failed-assert>
     </xsl:otherwise>
  </xsl:choose>
  <xsl:apply-templates select="*|comment()|processing-instruction()" mode="M0"/>

    Warning: on line 286 
  The preceding-sibling axis starting at a namespace node will never select anything
Warning: on line 311 
  The preceding-sibling axis starting at a namespace node will never select anything
Warning: on line 407 
  The child axis starting at an attribute node will never select anything
Warning: on line 407 
  The child axis starting at an attribute node will never select anything
Warning: on line 407 
  The child axis starting at an attribute node will never select anything
Warning: on line 436 
  The child axis starting at an attribute node will never select anything
Warning: on line 436 
  The child axis starting at an attribute node will never select anything
Warning: on line 436 

EDIT:

actually i transformed schematron to xslt in order to test it also in xslt. given was schematron for validating. so actually i have to validate through given schematron files, sample xml and java code for validating. main schematron and other files have more rules and patterns. but i removed most of them for sample code and easily testing. everything is validated successfully except attributes in elements.( e.g currencyId attribute). im using UgliSch (Ugli Schematron Validator) for schematron validation.

MainSchematron.xml:

<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns="http://purl.oclc.org/dsdl/schematron"
            xmlns:sch="http://purl.oclc.org/dsdl/schematron"
            xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"
            xmlns:ef="http://www.efatura.gov.tr/envelope-namespace">

    <sch:include href="UBL-TR_Codelist.xml#codes"/>
    <sch:include href="UBL-TR_Common_Schematron.xml#abstracts"/>

    <sch:ns prefix="cbc" uri="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />

    <sch:rule context="//cbc:CurrencyCode">
        <sch:extends rule="GeneralCurrencyCodeCheck"/>
    </sch:rule>
    <sch:rule context="//@currencyID">
        <sch:extends rule="GeneralCurrencyIDCheck"/>
    </sch:rule>


</sch:schema>

UBL-TR_Common_Schematron.xml:

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"
            xmlns="http://purl.oclc.org/dsdl/schematron">

    <sch:pattern name="AbstractRules" id="abstracts">
        <sch:p>Pattern for storing abstract rules</sch:p>

        <!-- Rule to validate currencyID Genel -->
        <sch:rule abstract="true" id="GeneralCurrencyIDCheck">
            <sch:assert test="contains($CurrencyCodeList, concat(',',.,','))">Geçersiz currencyID niteliği : '<sch:value-of select="."/>'. Geçerli değerler için kod listesine bakınız.</sch:assert>
        </sch:rule>


    </sch:pattern>
</sch:schema>

UBL-TR_Codelist.xml:

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"
            xmlns="http://purl.oclc.org/dsdl/schematron">

    <sch:pattern name="CodeList" id="codes">

        <sch:let name="CurrencyCodeList" value="',AED,AFN,ALL,AMD,ANG,AOA,ARS,AUD,AWG,AZN,BAM,BBD,BDT,BGN,BHD,BIF,BMD,BND,BOB,BOV,BRL,BSD,BTN,BWP,BYR,BZD,CAD,CDF,CHE,CHF,CHW,CLF,CLP,CNY,COP,COU,CRC,CUC,CUP,CVE,CZK,DJF,DKK,DOP,DZD,EEK,EGP,ERN,ETB,EUR,FJD,FKP,GBP,GEL,GHS,GIP,GMD,GNF,GTQ,GWP,GYD,HKD,HNL,HRK,HTG,HUF,IDR,ILS,INR,IQD,IRR,ISK,JMD,JOD,JPY,KES,KGS,KHR,KMF,KPW,KRW,KWD,KYD,KZT,LAK,LBP,LKR,LRD,LSL,LTL,LVL,LYD,MAD,MAD,MDL,MGA,MKD,MMK,MNT,MOP,MRO,MUR,MVR,MWK,MXN,MXV,MYR,MZN,NAD,NGN,NIO,NOK,NPR,NZD,OMR,PAB,PEN,PGK,PHP,PKR,PLN,PYG,QAR,RON,RSD,RUB,RWF,SAR,SBD,SCR,SDG,SEK,SGD,SHP,SLL,SOS,SRD,STD,SVC,SYP,SZL,THB,TJS,TMT,TND,TOP,TRY,TTD,TWD,TZS,UAH,UGX,USD,USN,USS,UYI,UYU,UZS,VEF,VND,VUV,WST,XAF,XAG,XAU,XBA,XBB,XBC,XBD,XCD,XDR,XFU,XOF,XPD,XPF,XPF,XPF,XPT,XTS,XXX,YER,ZAR,ZMK,ZWL,'"/>

        </sch:pattern>

</sch:schema>

sample.xml:

<sh:StandardBusinessDocument xsi:schemaLocation="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader PackageProxy_1_2.xsd" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:ef="http://www.efatura.gov.tr/package-namespace" xmlns:oa="http://www.openapplications.org/oagis/9" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:sh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ns9="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:ns11="urn:oasis:names:specification:ubl:schema:xsd:ApplicationResponse-2" xmlns:ns3="http://www.hr-xml.org/3" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <sh:StandardBusinessDocumentHeader>
        <sh:HeaderVersion>1.0</sh:HeaderVersion>
        <sh:Sender>
            <sh:Identifier>urn:mail:defaultgb@xxx.com.tr</sh:Identifier>
            <sh:ContactInformation>
                <sh:Contact>xxx Kurumsal Bilgi Sistemleri A.Ş</sh:Contact>
                <sh:ContactTypeIdentifier>UNVAN</sh:ContactTypeIdentifier>
            </sh:ContactInformation>
            <sh:ContactInformation>
                <sh:Contact>8110120507</sh:Contact>
                <sh:ContactTypeIdentifier>VKN_TCKN</sh:ContactTypeIdentifier>
            </sh:ContactInformation>
        </sh:Sender>
        <sh:Receiver>
            <sh:Identifier>urn:mail:defaultpk@xxx.com.tr</sh:Identifier>
            <sh:ContactInformation>
                <sh:Contact>KAKAR KURUMSAL BİLGİSİSTEMLERİ LTD.ŞTİ. Test Kullanıcısı</sh:Contact>
                <sh:ContactTypeIdentifier>UNVAN</sh:ContactTypeIdentifier>
            </sh:ContactInformation>
            <sh:ContactInformation>
                <sh:Contact>4545552073</sh:Contact>
                <sh:ContactTypeIdentifier>VKN_TCKN</sh:ContactTypeIdentifier>
            </sh:ContactInformation>
        </sh:Receiver>
        <sh:DocumentIdentification>
            <sh:Standard>UBL-TR</sh:Standard>
            <sh:TypeVersion>1.2</sh:TypeVersion>
            <sh:InstanceIdentifier>bb583542-a81a-4b45-87d6-e90596101a41</sh:InstanceIdentifier>
            <sh:Type>SENDERENVELOPE</sh:Type>
            <sh:MultipleType>false</sh:MultipleType>
            <sh:CreationDateAndTime>2016-01-06T16:27:25.759+02:00</sh:CreationDateAndTime>
        </sh:DocumentIdentification>
    </sh:StandardBusinessDocumentHeader>
    <ef:Package>
        <Elements>
            <ElementType>INVOICE</ElementType>
            <ElementCount>1</ElementCount>
            <ElementList>
                <ns9:Invoice>
                    <ext:UBLExtensions>
                        <ext:UBLExtension>
                            <ext:ExtensionContent>
                            ...
                            </ext:ExtensionContent>
                        </ext:UBLExtension>
                    </ext:UBLExtensions>
                    <cbc:UBLVersionID>2.1</cbc:UBLVersionID>
                    <cbc:CustomizationID>TR1.2</cbc:CustomizationID>
                    <cbc:ProfileID>TICARIFATURA</cbc:ProfileID>
                    <cbc:ID>PAZ2015000000012</cbc:ID>
                    <cbc:CopyIndicator>false</cbc:CopyIndicator>
                    <cbc:UUID>54b0dad2-e3a7-44ee-848a-cf7977000020</cbc:UUID>
                    <cbc:IssueDate>2016-01-06</cbc:IssueDate>
                    <cbc:InvoiceTypeCode>SATIS</cbc:InvoiceTypeCode>
                    <cbc:DocumentCurrencyCode>TRY</cbc:DocumentCurrencyCode>
                    <cbc:LineCountNumeric>0</cbc:LineCountNumeric>
                    <cac:Signature>
                        <cbc:ID schemeID="VKN_TCKN">8110120507</cbc:ID>
                        <cac:SignatoryParty>
                            <cbc:WebsiteURI>http://www.xxx.com.tr/</cbc:WebsiteURI>
                            <cac:PartyIdentification>
                                <cbc:ID schemeID="VKN">8110120507</cbc:ID>
                            </cac:PartyIdentification>
                            <cac:PartyName>
                                <cbc:Name>xxx Kurumsal Bilgi Sistemleri A.Ş</cbc:Name>
                            </cac:PartyName>
                            <cac:PostalAddress>
                                <cbc:StreetName>Besiktas Teknik Universitesi</cbc:StreetName>
                                <cbc:BuildingNumber>150/1G</cbc:BuildingNumber>
                                <cbc:CitySubdivisionName>Besıktas</cbc:CitySubdivisionName>
                                <cbc:CityName>Istanbul</cbc:CityName>
                                <cbc:PostalZone>06100</cbc:PostalZone>
                                <cac:Country>
                                    <cbc:Name>Turkiye</cbc:Name>
                                </cac:Country>
                            </cac:PostalAddress>
                        </cac:SignatoryParty>
                        <cac:DigitalSignatureAttachment>
                            <cac:ExternalReference>
                                <cbc:URI>#Signature</cbc:URI>
                            </cac:ExternalReference>
                        </cac:DigitalSignatureAttachment>
                    </cac:Signature>
                    <cac:AccountingSupplierParty>
                        <cac:Party>
                            <cac:PartyIdentification>
                                <cbc:ID schemeID="VKN">7221130507</cbc:ID>
                            </cac:PartyIdentification>
                            <cac:PartyName>
                                <cbc:Name>KAKAR KURUMSAL  LTD.ŞTİ.</cbc:Name>
                            </cac:PartyName>
                            <cac:PostalAddress>
                                <cbc:Room/>
                                <cbc:BuildingName/>
                                <cbc:BuildingNumber/>
                                <cbc:CitySubdivisionName>besiktas</cbc:CitySubdivisionName>
                                <cbc:CityName>istanbul</cbc:CityName>
                                <cbc:PostalZone/>
                                <cac:Country>
                                    <cbc:Name>ALMANYA</cbc:Name>
                                </cac:Country>
                            </cac:PostalAddress>
                            <cac:Contact>
                                <cbc:Telephone/>
                                <cbc:Telefax/>
                                <cbc:ElectronicMail/>
                            </cac:Contact>
                        </cac:Party>
                    </cac:AccountingSupplierParty>
                    <cac:AccountingCustomerParty>
                        <cac:Party>
                            <cbc:WebsiteURI/>
                            <cac:PartyIdentification>
                                <cbc:ID schemeID="VKN">2535552073</cbc:ID>
                            </cac:PartyIdentification>
                            <cac:PartyName>
                                <cbc:Name>KAKAR LTD.ŞTİ. Test Kullanıcısı</cbc:Name>
                            </cac:PartyName>
                            <cac:PostalAddress>
                                <cbc:ID/>
                                <cbc:Postbox/>
                                <cbc:Room/>
                                <cbc:StreetName/>
                                <cbc:BlockName/>
                                <cbc:BuildingName/>
                                <cbc:BuildingNumber/>
                                <cbc:CitySubdivisionName>besiktas</cbc:CitySubdivisionName>
                                <cbc:CityName>istanbul</cbc:CityName>
                                <cbc:PostalZone/>
                                <cbc:Region/>
                                <cbc:District/>
                                <cac:Country>
                                    <cbc:Name>TÜRKİYE</cbc:Name>
                                </cac:Country>
                            </cac:PostalAddress>
                            <cac:Contact>
                                <cbc:Telephone/>
                                <cbc:Telefax/>
                                <cbc:ElectronicMail/>
                            </cac:Contact>
                            <cac:Person>
                                <cbc:FirstName/>
                                <cbc:FamilyName/>
                            </cac:Person>
                        </cac:Party>
                    </cac:AccountingCustomerParty>
                    <cac:TaxTotal>
                        <cbc:TaxAmount currencyID="TRY">2.16</cbc:TaxAmount>
                        <cac:TaxSubtotal>
                            <cbc:TaxableAmount currencyID="asdasdasdasd">0</cbc:TaxableAmount>
                            <cbc:TaxAmount currencyID="TRY">2.16</cbc:TaxAmount>
                            <cbc:CalculationSequenceNumeric>0</cbc:CalculationSequenceNumeric>
                            <cbc:Percent>18</cbc:Percent>
                            <cac:TaxCategory>
                                <cac:TaxScheme>
                                    <cbc:Name>KDV</cbc:Name>
                                    <cbc:TaxTypeCode>0015</cbc:TaxTypeCode>
                                </cac:TaxScheme>
                            </cac:TaxCategory>
                        </cac:TaxSubtotal>
                    </cac:TaxTotal>
                    <cac:LegalMonetaryTotal>
                        <cbc:LineExtensionAmount currencyID="TRY">12</cbc:LineExtensionAmount>
                        <cbc:TaxExclusiveAmount currencyID="TRY">12</cbc:TaxExclusiveAmount>
                        <cbc:TaxInclusiveAmount currencyID="TRY">14.16</cbc:TaxInclusiveAmount>
                        <cbc:AllowanceTotalAmount currencyID="TRY">0</cbc:AllowanceTotalAmount>
                        <cbc:PayableAmount currencyID="TRY">14.16</cbc:PayableAmount>
                    </cac:LegalMonetaryTotal>
                    <cac:InvoiceLine>
                        <cbc:ID>1</cbc:ID>
                        <cbc:InvoicedQuantity unitCode="NIU">1</cbc:InvoicedQuantity>
                        <cbc:LineExtensionAmount currencyID="">12</cbc:LineExtensionAmount>
                        <cac:AllowanceCharge>
                            <cbc:ChargeIndicator>false</cbc:ChargeIndicator>
                            <cbc:MultiplierFactorNumeric>0</cbc:MultiplierFactorNumeric>
                            <cbc:Amount currencyID="">0</cbc:Amount>
                            <cbc:BaseAmount currencyID="">0</cbc:BaseAmount>
                        </cac:AllowanceCharge>
                        <cac:TaxTotal>
                            <cbc:TaxAmount currencyID="">2.16</cbc:TaxAmount>
                            <cac:TaxSubtotal>
                                <cbc:TaxableAmount currencyID="">0</cbc:TaxableAmount>
                                <cbc:TaxAmount currencyID="">2.16</cbc:TaxAmount>
                                <cbc:Percent>18</cbc:Percent>
                                <cac:TaxCategory>
                                    <cac:TaxScheme>
                                        <cbc:Name>KDV</cbc:Name>
                                        <cbc:TaxTypeCode>0015</cbc:TaxTypeCode>
                                    </cac:TaxScheme>
                                </cac:TaxCategory>
                            </cac:TaxSubtotal>
                        </cac:TaxTotal>
                        <cac:Item>
                            <cbc:Name>asdasd</cbc:Name>
                        </cac:Item>
                        <cac:Price>
                            <cbc:PriceAmount currencyID="TRY">12</cbc:PriceAmount>
                        </cac:Price>
                    </cac:InvoiceLine>
                </ns9:Invoice>
            </ElementList>
        </Elements>
    </ef:Package>
</sh:StandardBusinessDocument>

java :

  try (InputStream ubl = getClass().getResourceAsStream("/schematrons/UBL-TR_Main_Schematron.xml");) {

            SchemaFactory schemaFactory = SchemaFactory.newInstance(XmlSchemaNsUris.SCHEMATRON_NS_URI);
            Schema schema = schemaFactory.newSchema(new StreamSource(ubl));

            Validator validator = schema.newValidator();

            validator.setErrorHandler(validationErrorHandler);

            validator.validate(new StringSource(new String(binary,"UTF-8")));
        } catch (Exception e) {
            e.printStackTrace();
        }
Runomu
  • 411
  • 1
  • 8
  • 18
  • 2
    http://stackoverflow.com/help/mcve – michael.hor257k Jan 07 '16 at 14:43
  • [@Runomu](http://stackoverflow.com/users/4244531/runomu), Can you just provide the sample data so that some one can reproduce the issue? – Rao Jan 07 '16 at 16:47
  • @Rao i edited and improved my problem above. i will appreciate any help ! – Runomu Jan 07 '16 at 23:38
  • Those warnings are because the xsl that the schematron is transformed into has a statement of the form `` that shows up even under templates that work with attributes. It is just a warning that the statement serves no purpose, and isn't something to worry about (you'll get it if you have any rules working with attributes). – Matthew Feb 26 '16 at 07:22
  • I am trying to test your schemas, but you have not included the abstract rule **GeneralCurrencyCodeCheck**, so it isn't building correctly. – Matthew Feb 26 '16 at 07:22
  • It looks like it is working to me. All six `currencyID=''` attributes are resulting in _svrl:failed-assert_ elements in the output. – Matthew Feb 26 '16 at 07:30
  • @Matthew later i found out that schematron version was the problem for me. but anyway thank lot for help! – Runomu Apr 16 '16 at 11:33
  • @Runomu i use UgliSch 1.0.4 and got same problem (ignoring attributes). Can you explain how to fix it? – Daedelus Apr 27 '16 at 06:11
  • @Daedelus its little bit long time. but as far as i remember. i did schematron validation for xlst 2.0. so i managed to solve problem. and warnings above dont point to real problem. – Runomu May 03 '16 at 14:24

0 Answers0