我一直试图通过xslt验证xml几个小时。我有以下xsl表单用于xml验证。每次我尝试验证xml时,我都会收到以下警告,并忽略xml中的空currencyid属性,xml验证虽然不是。有没有人知道为什么忽略和验证它?
<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
编辑:
实际上我将schematron转换为xslt,以便在xslt中测试它。给出了schematron进行验证。所以实际上我必须通过给定的schematron文件验证,样本xml和java代码进行验证。主要的schematron和其他文件有更多的规则和模式。但我删除了大部分样本代码并轻松测试。除了元素中的属性外,所有内容都已成功验证(例如currencyId属性)。我使用UgliSch(Ugli Schematron Validator)进行架构验证。
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();
}