java - Xml validation with xsl -
i have been trying validate xml through xslt couple of hours. have following xsl form xml validation. every time try validate xml, following warnings below , empty currencyid attributes in xml ignored , xml validate although not. has idea why ignored , 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 preceding-sibling axis starting @ namespace node never select warning: on line 311 preceding-sibling axis starting @ namespace node never select warning: on line 407 child axis starting @ attribute node never select warning: on line 407 child axis starting @ attribute node never select warning: on line 407 child axis starting @ attribute node never select warning: on line 436 child axis starting @ attribute node never select warning: on line 436 child axis starting @ attribute node never select warning: on line 436
edit:
actually transformed schematron xslt in order test in xslt. given schematron validating. have validate through given schematron files, sample xml , java code validating. main schematron , other files have more rules , patterns. removed of them sample code , testing. validated except attributes in elements.( e.g currencyid attribute). im using uglisch (ugli schematron validator) 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 storing abstract rules</sch:p> <!-- rule 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(); }
Comments
Post a Comment