zatca 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -2
  3. data/bin/console +0 -0
  4. data/bin/setup +0 -0
  5. data/einvoicing-sdk/Apps/fatoora +12 -0
  6. data/einvoicing-sdk/Apps/fatoora.bat +16 -0
  7. data/einvoicing-sdk/Apps/global.json +1 -0
  8. data/einvoicing-sdk/Apps/jq.exe +0 -0
  9. data/einvoicing-sdk/Apps/zatca-einvoicing-sdk-238-R3.2.7.jar +0 -0
  10. data/einvoicing-sdk/Configuration/config.json +11 -0
  11. data/einvoicing-sdk/Configuration/defaults.json +11 -0
  12. data/einvoicing-sdk/Configuration/jq.exe +0 -0
  13. data/einvoicing-sdk/Configuration/usage.txt +16 -0
  14. data/einvoicing-sdk/Data/Certificates/cert.pem +1 -0
  15. data/einvoicing-sdk/Data/Certificates/ec-secp256k1-priv-key.pem +1 -0
  16. data/einvoicing-sdk/Data/Input/csr-config-example-AR-VAT-Group.properties +9 -0
  17. data/einvoicing-sdk/Data/Input/csr-config-example-AR.properties +9 -0
  18. data/einvoicing-sdk/Data/Input/csr-config-example-EN-VAT-group.properties +9 -0
  19. data/einvoicing-sdk/Data/Input/csr-config-example-EN.properties +9 -0
  20. data/einvoicing-sdk/Data/Input/csr-config-template.properties +9 -0
  21. data/einvoicing-sdk/Data/PIH/pih.txt +1 -0
  22. data/einvoicing-sdk/Data/Rules/schematrons/20210819_ZATCA_E-invoice_Validation_Rules.xsl +2844 -0
  23. data/einvoicing-sdk/Data/Rules/schematrons/CEN-EN16931-UBL.xsl +1973 -0
  24. data/einvoicing-sdk/Data/Samples/PDF-A3/Simplified Debit Note.pdf +0 -0
  25. data/einvoicing-sdk/Data/Samples/PDF-A3/Standard Credit Note.pdf +0 -0
  26. data/einvoicing-sdk/Data/Samples/PDF-A3/Standard Debit Note.pdf +0 -0
  27. data/einvoicing-sdk/Data/Samples/PDF-A3/Standard Invoice.pdf +0 -0
  28. data/einvoicing-sdk/Data/Samples/PDF-A3/Tax_Invoice_USD.pdf +0 -0
  29. data/einvoicing-sdk/Data/Samples/Simplified/Credit/Simplified_Credit_Note.xml +300 -0
  30. data/einvoicing-sdk/Data/Samples/Simplified/Credit/Simplified_Credit_Note_Error.xml +225 -0
  31. data/einvoicing-sdk/Data/Samples/Simplified/Debit/Simplified_Debit_Note.xml +211 -0
  32. data/einvoicing-sdk/Data/Samples/Simplified/Debit/Simplified_Debit_Note_Error.xml +226 -0
  33. data/einvoicing-sdk/Data/Samples/Simplified/Invoice/Additional_Simplified_Invoices/Out_Of_Scope_Simplified_Invoice.xml +207 -0
  34. data/einvoicing-sdk/Data/Samples/Simplified/Invoice/Additional_Simplified_Invoices/Simplified_Invoice_USD.xml +246 -0
  35. data/einvoicing-sdk/Data/Samples/Simplified/Invoice/Simplified_Invoice.xml +246 -0
  36. data/einvoicing-sdk/Data/Samples/Simplified/Invoice/Simplified_Invoice_Error.xml +228 -0
  37. data/einvoicing-sdk/Data/Samples/Standard/Credit/Standard_Credit_Note.xml +227 -0
  38. data/einvoicing-sdk/Data/Samples/Standard/Credit/Standard_Credit_Note_Error.xml +224 -0
  39. data/einvoicing-sdk/Data/Samples/Standard/Debit/Standard_Debit_Note.xml +227 -0
  40. data/einvoicing-sdk/Data/Samples/Standard/Debit/Standard_Debit_Note_Error.xml +226 -0
  41. data/einvoicing-sdk/Data/Samples/Standard/Invoice/Additional_Standard_Invoices/Exempt_Standard_Invoice.xml +227 -0
  42. data/einvoicing-sdk/Data/Samples/Standard/Invoice/Additional_Standard_Invoices/Standard_Invoice_USD.xml +227 -0
  43. data/einvoicing-sdk/Data/Samples/Standard/Invoice/Additional_Standard_Invoices/Zero_Rate_Standard_Invoice.xml +227 -0
  44. data/einvoicing-sdk/Data/Samples/Standard/Invoice/Sample Invoice[Advance Payements] - 1.xml +294 -0
  45. data/einvoicing-sdk/Data/Samples/Standard/Invoice/Sample Invoice[Advance Payements] - 2.xml +432 -0
  46. data/einvoicing-sdk/Data/Samples/Standard/Invoice/Standard_Invoice.xml +222 -0
  47. data/einvoicing-sdk/Data/Samples/Standard/Invoice/Standard_Invoice_Error.xml +228 -0
  48. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/CCTS_CCT_SchemaModule-2.1.xsd +731 -0
  49. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-CommonAggregateComponents-2.1.xsd +44365 -0
  50. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-CommonBasicComponents-2.1.xsd +5389 -0
  51. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-CommonExtensionComponents-2.1.xsd +223 -0
  52. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-CommonSignatureComponents-2.1.xsd +101 -0
  53. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-CoreComponentParameters-2.1.xsd +63 -0
  54. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-ExtensionContentDataType-2.1.xsd +89 -0
  55. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-QualifiedDataTypes-2.1.xsd +69 -0
  56. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-SignatureAggregateComponents-2.1.xsd +138 -0
  57. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-SignatureBasicComponents-2.1.xsd +78 -0
  58. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-UnqualifiedDataTypes-2.1.xsd +553 -0
  59. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-XAdESv132-2.1.xsd +476 -0
  60. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-XAdESv141-2.1.xsd +25 -0
  61. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/common/UBL-xmldsig-core-schema-2.1.xsd +330 -0
  62. data/einvoicing-sdk/Data/Schemas/xsds/UBL2.1/xsd/maindoc/UBL-Invoice-2.1.xsd +1002 -0
  63. data/einvoicing-sdk/Dockerfile +26 -0
  64. data/einvoicing-sdk/LICENSE.txt +56 -0
  65. data/einvoicing-sdk/Lib/.Net/DLL/BouncyCastle.Crypto.dll +0 -0
  66. data/einvoicing-sdk/Lib/.Net/DLL/IKVM.OpenJDK.Core.dll +0 -0
  67. data/einvoicing-sdk/Lib/.Net/DLL/IKVM.OpenJDK.Text.dll +0 -0
  68. data/einvoicing-sdk/Lib/.Net/DLL/IKVM.OpenJDK.Util.dll +0 -0
  69. data/einvoicing-sdk/Lib/.Net/DLL/IKVM.OpenJDK.XML.API.dll +0 -0
  70. data/einvoicing-sdk/Lib/.Net/DLL/IKVM.Runtime.dll +0 -0
  71. data/einvoicing-sdk/Lib/.Net/DLL/SDKNETFrameWorkLib.dll +0 -0
  72. data/einvoicing-sdk/Lib/.Net/DLL/SDKNETFrameWorkLib.dll.config +43 -0
  73. data/einvoicing-sdk/Lib/.Net/DLL/SDKNETFrameWorkLib.pdb +0 -0
  74. data/einvoicing-sdk/Lib/.Net/DLL/System.Net.Http.dll +0 -0
  75. data/einvoicing-sdk/Lib/.Net/DLL/saxon-he-10.8.dll +0 -0
  76. data/einvoicing-sdk/Lib/.Net/DLL/saxon-he-api-10.8.dll +0 -0
  77. data/einvoicing-sdk/Lib/.Net/DLL/saxon-he-api-10.8.xml +11759 -0
  78. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/.vs/SDKNETFrameworkTest/FileContentIndex/3f204b7a-faba-42d8-8288-8b6fe516555c.vsidx +0 -0
  79. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/.vs/SDKNETFrameworkTest/FileContentIndex/f95b6f91-c110-4b7a-bb49-3fc6bde85b13.vsidx +0 -0
  80. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/.vs/SDKNETFrameworkTest/FileContentIndex/read.lock +0 -0
  81. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/.vs/SDKNETFrameworkTest/v17/.suo +0 -0
  82. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/App.config +14 -0
  83. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/BouncyCastle.Crypto.dll +0 -0
  84. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/CSRGeneratorOpenSSL.cs +58 -0
  85. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/IKVM.OpenJDK.Core.dll +0 -0
  86. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/IKVM.OpenJDK.Text.dll +0 -0
  87. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/IKVM.OpenJDK.Util.dll +0 -0
  88. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/IKVM.OpenJDK.XML.API.dll +0 -0
  89. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/IKVM.Runtime.dll +0 -0
  90. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/Program.cs +194 -0
  91. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/Properties/AssemblyInfo.cs +36 -0
  92. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/Readme.txt +8 -0
  93. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameWorkLib.dll +0 -0
  94. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameWorkLib.dll.config +43 -0
  95. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameWorkLib.pdb +0 -0
  96. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameworkTest.csproj +120 -0
  97. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameworkTest.exe +0 -0
  98. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameworkTest.exe.config +20 -0
  99. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameworkTest.pdb +0 -0
  100. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/SDKNETFrameworkTest.sln +25 -0
  101. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/BouncyCastle.Crypto.dll +0 -0
  102. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/Data/certificate.txt +1 -0
  103. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/Data/pih.txt +1 -0
  104. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/Data/privateKey.txt +1 -0
  105. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/IKVM.OpenJDK.Core.dll +0 -0
  106. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/IKVM.OpenJDK.Text.dll +0 -0
  107. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/IKVM.OpenJDK.Util.dll +0 -0
  108. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/IKVM.OpenJDK.XML.API.dll +0 -0
  109. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/IKVM.Runtime.dll +0 -0
  110. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/SDKNETFrameWorkLib.dll +0 -0
  111. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/SDKNETFrameWorkLib.dll.config +43 -0
  112. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/SDKNETFrameWorkLib.pdb +0 -0
  113. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/SDKNETFrameworkTest.exe +0 -0
  114. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/SDKNETFrameworkTest.exe.config +20 -0
  115. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/SDKNETFrameworkTest.pdb +0 -0
  116. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/System.Net.Http.dll +0 -0
  117. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/saxon-he-10.8.dll +0 -0
  118. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/saxon-he-api-10.8.dll +0 -0
  119. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/bin/Debug/saxon-he-api-10.8.xml +11759 -0
  120. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs +4 -0
  121. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/DesignTimeResolveAssemblyReferences.cache +0 -0
  122. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache +0 -0
  123. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.csproj.AssemblyReference.cache +0 -0
  124. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.csproj.CopyComplete +0 -0
  125. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.csproj.CoreCompileInputs.cache +1 -0
  126. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.csproj.FileListAbsolute.txt +22 -0
  127. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.csproj.SuggestedBindingRedirects.cache +0 -0
  128. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.exe +0 -0
  129. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/obj/Debug/SDKNETFrameworkTest.pdb +0 -0
  130. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/saxon-he-10.8.dll +0 -0
  131. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/saxon-he-api-10.8.dll +0 -0
  132. data/einvoicing-sdk/Lib/.Net/SDKNETFrameworkTest/saxon-he-api-10.8.xml +11759 -0
  133. data/einvoicing-sdk/Lib/.Net/Test/BouncyCastle.Crypto.dll +0 -0
  134. data/einvoicing-sdk/Lib/.Net/Test/IKVM.OpenJDK.Core.dll +0 -0
  135. data/einvoicing-sdk/Lib/.Net/Test/IKVM.OpenJDK.Text.dll +0 -0
  136. data/einvoicing-sdk/Lib/.Net/Test/IKVM.OpenJDK.Util.dll +0 -0
  137. data/einvoicing-sdk/Lib/.Net/Test/IKVM.OpenJDK.XML.API.dll +0 -0
  138. data/einvoicing-sdk/Lib/.Net/Test/IKVM.Runtime.dll +0 -0
  139. data/einvoicing-sdk/Lib/.Net/Test/SDKNETFrameWorkLib.dll +0 -0
  140. data/einvoicing-sdk/Lib/.Net/Test/SDKNETFrameWorkLib.dll.config +43 -0
  141. data/einvoicing-sdk/Lib/.Net/Test/SDKNETFrameWorkLib.pdb +0 -0
  142. data/einvoicing-sdk/Lib/.Net/Test/SDKNETFrameworkTest.exe +0 -0
  143. data/einvoicing-sdk/Lib/.Net/Test/SDKNETFrameworkTest.exe.config +20 -0
  144. data/einvoicing-sdk/Lib/.Net/Test/SDKNETFrameworkTest.pdb +0 -0
  145. data/einvoicing-sdk/Lib/.Net/Test/saxon-he-10.8.dll +0 -0
  146. data/einvoicing-sdk/Lib/.Net/Test/saxon-he-api-10.8.dll +0 -0
  147. data/einvoicing-sdk/Lib/.Net/Test/saxon-he-api-10.8.xml +11759 -0
  148. data/einvoicing-sdk/README.md +15 -0
  149. data/einvoicing-sdk/Readme/readme.docx +0 -0
  150. data/einvoicing-sdk/Readme/readme.md +674 -0
  151. data/einvoicing-sdk/Readme/readme.pdf +0 -0
  152. data/einvoicing-sdk/Readme/~$readme.docx +0 -0
  153. data/einvoicing-sdk/docker-compose.yml +12 -0
  154. data/einvoicing-sdk/install.bat +74 -0
  155. data/einvoicing-sdk/install.sh +74 -0
  156. data/lib/zatca/client.rb +173 -0
  157. data/lib/zatca/hacks.rb +45 -0
  158. data/lib/zatca/hashing.rb +18 -0
  159. data/lib/zatca/qr_code_extractor.rb +31 -0
  160. data/lib/zatca/qr_code_generator.rb +9 -2
  161. data/lib/zatca/signing/certificate.rb +78 -0
  162. data/lib/zatca/signing/csr.rb +220 -0
  163. data/lib/zatca/signing/ecdsa.rb +59 -0
  164. data/lib/zatca/tag.rb +18 -8
  165. data/lib/zatca/tags.rb +9 -1
  166. data/lib/zatca/tags_schema.rb +5 -5
  167. data/lib/zatca/types.rb +7 -0
  168. data/lib/zatca/ubl/base_component.rb +142 -0
  169. data/lib/zatca/ubl/builder.rb +166 -0
  170. data/lib/zatca/ubl/common_aggregate_components/allowance_charge.rb +64 -0
  171. data/lib/zatca/ubl/common_aggregate_components/classified_tax_category.rb +25 -0
  172. data/lib/zatca/ubl/common_aggregate_components/delivery.rb +27 -0
  173. data/lib/zatca/ubl/common_aggregate_components/invoice_line.rb +63 -0
  174. data/lib/zatca/ubl/common_aggregate_components/item.rb +21 -0
  175. data/lib/zatca/ubl/common_aggregate_components/legal_monetary_total.rb +59 -0
  176. data/lib/zatca/ubl/common_aggregate_components/party.rb +28 -0
  177. data/lib/zatca/ubl/common_aggregate_components/party_identification.rb +25 -0
  178. data/lib/zatca/ubl/common_aggregate_components/party_legal_entity.rb +19 -0
  179. data/lib/zatca/ubl/common_aggregate_components/party_tax_scheme.rb +30 -0
  180. data/lib/zatca/ubl/common_aggregate_components/postal_address.rb +59 -0
  181. data/lib/zatca/ubl/common_aggregate_components/price.rb +20 -0
  182. data/lib/zatca/ubl/common_aggregate_components/tax_category.rb +56 -0
  183. data/lib/zatca/ubl/common_aggregate_components/tax_total.rb +58 -0
  184. data/lib/zatca/ubl/common_aggregate_components.rb +2 -0
  185. data/lib/zatca/ubl/invoice.rb +481 -0
  186. data/lib/zatca/ubl/invoice_subtype_builder.rb +50 -0
  187. data/lib/zatca/ubl/signing/cert.rb +48 -0
  188. data/lib/zatca/ubl/signing/invoice_signed_data_reference.rb +44 -0
  189. data/lib/zatca/ubl/signing/key_info.rb +25 -0
  190. data/lib/zatca/ubl/signing/object.rb +20 -0
  191. data/lib/zatca/ubl/signing/qualifying_properties.rb +27 -0
  192. data/lib/zatca/ubl/signing/signature.rb +50 -0
  193. data/lib/zatca/ubl/signing/signature_information.rb +19 -0
  194. data/lib/zatca/ubl/signing/signature_properties_reference.rb +26 -0
  195. data/lib/zatca/ubl/signing/signed_info.rb +21 -0
  196. data/lib/zatca/ubl/signing/signed_properties.rb +81 -0
  197. data/lib/zatca/ubl/signing/signed_signature_properties.rb +23 -0
  198. data/lib/zatca/ubl/signing/ubl_document_signatures.rb +25 -0
  199. data/lib/zatca/ubl/signing/ubl_extension.rb +22 -0
  200. data/lib/zatca/ubl/signing/ubl_extensions.rb +17 -0
  201. data/lib/zatca/ubl/signing.rb +2 -0
  202. data/lib/zatca/ubl.rb +2 -0
  203. data/lib/zatca/version.rb +1 -1
  204. data/lib/zatca.rb +27 -3
  205. data/zatca.gemspec +52 -0
  206. metadata +318 -10
  207. data/Gemfile.lock +0 -100
@@ -0,0 +1,2844 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+
4
+ This file is part of Zakat, Tax and Customs Authority "ZATCA" e-Invoicing toolkit SDK.
5
+
6
+ Copyright 2021 ZATCA licensed under the GNU LGPL v3.
7
+
8
+ The License text is included within the LICENSE.txt file in the root folder.
9
+
10
+ -->
11
+ <xsl:transform xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
12
+ xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
13
+ xmlns:cn="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2"
14
+ xmlns:dn="urn:oasis:names:specification:ubl:schema:xsd:DebitNote-2"
15
+ xmlns:error="https://doi.org/10.5281/zenodo.1495494#error"
16
+ xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
17
+ xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2"
18
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
19
+ xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2"
20
+ xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2"
21
+ xmlns:sch="http://purl.oclc.org/dsdl/schematron"
22
+ xmlns:schxslt="https://doi.org/10.5281/zenodo.1495494"
23
+ xmlns:schxslt-api="https://doi.org/10.5281/zenodo.1495494#api"
24
+ xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2"
25
+ xmlns:ubl="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
26
+ xmlns:udt="urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2"
27
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
28
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
29
+ <rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/"
30
+ xmlns:dct="http://purl.org/dc/terms/"
31
+ xmlns:skos="http://www.w3.org/2004/02/skos/core#">
32
+ <dct:creator>
33
+ <dct:Agent>
34
+ <skos:prefLabel>SchXslt/${project.version} SAXON/HE 10.5</skos:prefLabel>
35
+ <schxslt.compile.typed-variables xmlns="https://doi.org/10.5281/zenodo.1495494#">true</schxslt.compile.typed-variables>
36
+ </dct:Agent>
37
+ </dct:creator>
38
+ <dct:created>2021-08-31T19:22:55.011988533+02:00</dct:created>
39
+ </rdf:Description>
40
+ <xsl:output indent="yes"/>
41
+ <xsl:template match="/">
42
+ <xsl:variable name="metadata" as="element()?">
43
+ <svrl:metadata xmlns:dct="http://purl.org/dc/terms/"
44
+ xmlns:skos="http://www.w3.org/2004/02/skos/core#"
45
+ xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
46
+ <dct:creator>
47
+ <dct:Agent>
48
+ <skos:prefLabel>
49
+ <xsl:variable name="prefix" as="xs:string?" select="if (doc-available('')) then in-scope-prefixes(document('')/*[1])[namespace-uri-for-prefix(., document('')/*[1]) eq 'http://www.w3.org/1999/XSL/Transform'][1] else ()"/>
50
+ <xsl:choose>
51
+ <xsl:when test="empty($prefix)">Unknown</xsl:when>
52
+ <xsl:otherwise>
53
+ <xsl:value-of separator="/" select="(system-property(concat($prefix, ':product-name')), system-property(concat($prefix,':product-version')))"/>
54
+ </xsl:otherwise>
55
+ </xsl:choose>
56
+ </skos:prefLabel>
57
+ </dct:Agent>
58
+ </dct:creator>
59
+ <dct:created>
60
+ <xsl:value-of select="current-dateTime()"/>
61
+ </dct:created>
62
+ <dct:source>
63
+ <rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/">
64
+ <dct:creator>
65
+ <dct:Agent>
66
+ <skos:prefLabel>SchXslt/${project.version} SAXON/HE 10.5</skos:prefLabel>
67
+ <schxslt.compile.typed-variables xmlns="https://doi.org/10.5281/zenodo.1495494#">true</schxslt.compile.typed-variables>
68
+ </dct:Agent>
69
+ </dct:creator>
70
+ <dct:created>2021-08-31T19:22:55.011988533+02:00</dct:created>
71
+ </rdf:Description>
72
+ </dct:source>
73
+ </svrl:metadata>
74
+ </xsl:variable>
75
+ <xsl:variable name="report" as="element(schxslt:report)">
76
+ <schxslt:report>
77
+ <xsl:call-template name="d7e29"/>
78
+ </schxslt:report>
79
+ </xsl:variable>
80
+ <xsl:variable name="schxslt:report" as="node()*">
81
+ <xsl:sequence select="$metadata"/>
82
+ <xsl:for-each select="$report/schxslt:pattern">
83
+ <xsl:sequence select="node()"/>
84
+ <xsl:sequence select="$report/schxslt:rule[@pattern = current()/@id]/node()"/>
85
+ </xsl:for-each>
86
+ </xsl:variable>
87
+ <svrl:schematron-output xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
88
+ <svrl:ns-prefix-in-attribute-values prefix="ext" uri="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"/>
89
+ <svrl:ns-prefix-in-attribute-values prefix="cbc" uri="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"/>
90
+ <svrl:ns-prefix-in-attribute-values prefix="cac" uri="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"/>
91
+ <svrl:ns-prefix-in-attribute-values prefix="sig" uri="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2"/>
92
+ <svrl:ns-prefix-in-attribute-values prefix="sac" uri="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2"/>
93
+ <svrl:ns-prefix-in-attribute-values prefix="sbc" uri="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2"/>
94
+ <svrl:ns-prefix-in-attribute-values prefix="qdt" uri="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2"/>
95
+ <svrl:ns-prefix-in-attribute-values prefix="udt" uri="urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2"/>
96
+ <svrl:ns-prefix-in-attribute-values prefix="cn" uri="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2"/>
97
+ <svrl:ns-prefix-in-attribute-values prefix="dn" uri="urn:oasis:names:specification:ubl:schema:xsd:DebitNote-2"/>
98
+ <svrl:ns-prefix-in-attribute-values prefix="ubl" uri="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"/>
99
+ <svrl:ns-prefix-in-attribute-values prefix="xs" uri="http://www.w3.org/2001/XMLSchema"/>
100
+ <xsl:sequence select="$schxslt:report"/>
101
+ </svrl:schematron-output>
102
+ </xsl:template>
103
+ <xsl:template match="text() | @*" mode="#all" priority="-10"/>
104
+ <xsl:template match="*" mode="#all" priority="-10">
105
+ <xsl:apply-templates mode="#current" select="@*"/>
106
+ <xsl:apply-templates mode="#current" select="node()"/>
107
+ </xsl:template>
108
+ <xsl:template name="d7e29">
109
+ <schxslt:pattern id="d7e29">
110
+ <xsl:if test="exists(base-uri(/))">
111
+ <xsl:attribute name="documents" select="base-uri(/)"/>
112
+ </xsl:if>
113
+ <xsl:for-each select="/">
114
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules">
115
+ <xsl:attribute name="documents" select="base-uri(.)"/>
116
+ </svrl:active-pattern>
117
+ </xsl:for-each>
118
+ </schxslt:pattern>
119
+ <schxslt:pattern id="d7e185">
120
+ <xsl:if test="exists(base-uri(/))">
121
+ <xsl:attribute name="documents" select="base-uri(/)"/>
122
+ </xsl:if>
123
+ <xsl:for-each select="/">
124
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_Attachment_QR_binary">
125
+ <xsl:attribute name="documents" select="base-uri(.)"/>
126
+ </svrl:active-pattern>
127
+ </xsl:for-each>
128
+ </schxslt:pattern>
129
+ <schxslt:pattern id="d7e194">
130
+ <xsl:if test="exists(base-uri(/))">
131
+ <xsl:attribute name="documents" select="base-uri(/)"/>
132
+ </xsl:if>
133
+ <xsl:for-each select="/">
134
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_customerParty_HQ">
135
+ <xsl:attribute name="documents" select="base-uri(.)"/>
136
+ </svrl:active-pattern>
137
+ </xsl:for-each>
138
+ </schxslt:pattern>
139
+ <schxslt:pattern id="d7e203">
140
+ <xsl:if test="exists(base-uri(/))">
141
+ <xsl:attribute name="documents" select="base-uri(/)"/>
142
+ </xsl:if>
143
+ <xsl:for-each select="/">
144
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_companyId_HQ">
145
+ <xsl:attribute name="documents" select="base-uri(.)"/>
146
+ </svrl:active-pattern>
147
+ </xsl:for-each>
148
+ </schxslt:pattern>
149
+ <schxslt:pattern id="d7e212">
150
+ <xsl:if test="exists(base-uri(/))">
151
+ <xsl:attribute name="documents" select="base-uri(/)"/>
152
+ </xsl:if>
153
+ <xsl:for-each select="/">
154
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_customerParty_SA">
155
+ <xsl:attribute name="documents" select="base-uri(.)"/>
156
+ </svrl:active-pattern>
157
+ </xsl:for-each>
158
+ </schxslt:pattern>
159
+ <schxslt:pattern id="d7e225">
160
+ <xsl:if test="exists(base-uri(/))">
161
+ <xsl:attribute name="documents" select="base-uri(/)"/>
162
+ </xsl:if>
163
+ <xsl:for-each select="/">
164
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_typeCode_01">
165
+ <xsl:attribute name="documents" select="base-uri(.)"/>
166
+ </svrl:active-pattern>
167
+ </xsl:for-each>
168
+ </schxslt:pattern>
169
+ <schxslt:pattern id="d7e246">
170
+ <xsl:if test="exists(base-uri(/))">
171
+ <xsl:attribute name="documents" select="base-uri(/)"/>
172
+ </xsl:if>
173
+ <xsl:for-each select="/">
174
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_typeCode_01_388">
175
+ <xsl:attribute name="documents" select="base-uri(.)"/>
176
+ </svrl:active-pattern>
177
+ </xsl:for-each>
178
+ </schxslt:pattern>
179
+ <schxslt:pattern id="d7e255">
180
+ <xsl:if test="exists(base-uri(/))">
181
+ <xsl:attribute name="documents" select="base-uri(/)"/>
182
+ </xsl:if>
183
+ <xsl:for-each select="/">
184
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_typeCode_01_Registration">
185
+ <xsl:attribute name="documents" select="base-uri(.)"/>
186
+ </svrl:active-pattern>
187
+ </xsl:for-each>
188
+ </schxslt:pattern>
189
+ <schxslt:pattern id="d7e264">
190
+ <xsl:if test="exists(base-uri(/))">
191
+ <xsl:attribute name="documents" select="base-uri(/)"/>
192
+ </xsl:if>
193
+ <xsl:for-each select="/">
194
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_Code_383_381">
195
+ <xsl:attribute name="documents" select="base-uri(.)"/>
196
+ </svrl:active-pattern>
197
+ </xsl:for-each>
198
+ </schxslt:pattern>
199
+ <schxslt:pattern id="d7e276">
200
+ <xsl:if test="exists(base-uri(/))">
201
+ <xsl:attribute name="documents" select="base-uri(/)"/>
202
+ </xsl:if>
203
+ <xsl:for-each select="/">
204
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_typeCode_02">
205
+ <xsl:attribute name="documents" select="base-uri(.)"/>
206
+ </svrl:active-pattern>
207
+ </xsl:for-each>
208
+ </schxslt:pattern>
209
+ <schxslt:pattern id="d7e291">
210
+ <xsl:if test="exists(base-uri(/))">
211
+ <xsl:attribute name="documents" select="base-uri(/)"/>
212
+ </xsl:if>
213
+ <xsl:for-each select="/">
214
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_typeCode_5">
215
+ <xsl:attribute name="documents" select="base-uri(.)"/>
216
+ </svrl:active-pattern>
217
+ </xsl:for-each>
218
+ </schxslt:pattern>
219
+ <schxslt:pattern id="d7e301">
220
+ <xsl:if test="exists(base-uri(/))">
221
+ <xsl:attribute name="documents" select="base-uri(/)"/>
222
+ </xsl:if>
223
+ <xsl:for-each select="/">
224
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_typeCode_5_0_Company">
225
+ <xsl:attribute name="documents" select="base-uri(.)"/>
226
+ </svrl:active-pattern>
227
+ </xsl:for-each>
228
+ </schxslt:pattern>
229
+ <schxslt:pattern id="d7e310">
230
+ <xsl:if test="exists(base-uri(/))">
231
+ <xsl:attribute name="documents" select="base-uri(/)"/>
232
+ </xsl:if>
233
+ <xsl:for-each select="/">
234
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_typeCode_5__HQ">
235
+ <xsl:attribute name="documents" select="base-uri(.)"/>
236
+ </svrl:active-pattern>
237
+ </xsl:for-each>
238
+ </schxslt:pattern>
239
+ <schxslt:pattern id="d7e319">
240
+ <xsl:if test="exists(base-uri(/))">
241
+ <xsl:attribute name="documents" select="base-uri(/)"/>
242
+ </xsl:if>
243
+ <xsl:for-each select="/">
244
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CustomRules_typeCode_5_0_HQ">
245
+ <xsl:attribute name="documents" select="base-uri(.)"/>
246
+ </svrl:active-pattern>
247
+ </xsl:for-each>
248
+ </schxslt:pattern>
249
+ <schxslt:pattern id="d7e328">
250
+ <xsl:if test="exists(base-uri(/))">
251
+ <xsl:attribute name="documents" select="base-uri(/)"/>
252
+ </xsl:if>
253
+ <xsl:for-each select="/">
254
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="Decimals">
255
+ <xsl:attribute name="documents" select="base-uri(.)"/>
256
+ </svrl:active-pattern>
257
+ </xsl:for-each>
258
+ </schxslt:pattern>
259
+ <schxslt:pattern id="d7e355">
260
+ <xsl:if test="exists(base-uri(/))">
261
+ <xsl:attribute name="documents" select="base-uri(/)"/>
262
+ </xsl:if>
263
+ <xsl:for-each select="/">
264
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="CodeList">
265
+ <xsl:attribute name="documents" select="base-uri(.)"/>
266
+ </svrl:active-pattern>
267
+ </xsl:for-each>
268
+ </schxslt:pattern>
269
+ <schxslt:pattern id="d7e385">
270
+ <xsl:if test="exists(base-uri(/))">
271
+ <xsl:attribute name="documents" select="base-uri(/)"/>
272
+ </xsl:if>
273
+ <xsl:for-each select="/">
274
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="Formats_allfields">
275
+ <xsl:attribute name="documents" select="base-uri(.)"/>
276
+ </svrl:active-pattern>
277
+ </xsl:for-each>
278
+ </schxslt:pattern>
279
+ <schxslt:pattern id="d7e395">
280
+ <xsl:if test="exists(base-uri(/))">
281
+ <xsl:attribute name="documents" select="base-uri(/)"/>
282
+ </xsl:if>
283
+ <xsl:for-each select="/">
284
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="Formats">
285
+ <xsl:attribute name="documents" select="base-uri(.)"/>
286
+ </svrl:active-pattern>
287
+ </xsl:for-each>
288
+ </schxslt:pattern>
289
+ <schxslt:pattern id="d7e416">
290
+ <xsl:if test="exists(base-uri(/))">
291
+ <xsl:attribute name="documents" select="base-uri(/)"/>
292
+ </xsl:if>
293
+ <xsl:for-each select="/">
294
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="EN16931">
295
+ <xsl:attribute name="documents" select="base-uri(.)"/>
296
+ </svrl:active-pattern>
297
+ </xsl:for-each>
298
+ </schxslt:pattern>
299
+ <schxslt:pattern id="d7e474">
300
+ <xsl:if test="exists(base-uri(/))">
301
+ <xsl:attribute name="documents" select="base-uri(/)"/>
302
+ </xsl:if>
303
+ <xsl:for-each select="/">
304
+ <svrl:active-pattern xmlns:svrl="http://purl.oclc.org/dsdl/svrl" id="EN16931_baseAmount">
305
+ <xsl:attribute name="documents" select="base-uri(.)"/>
306
+ </svrl:active-pattern>
307
+ </xsl:for-each>
308
+ </schxslt:pattern>
309
+ <xsl:apply-templates mode="d7e29" select="/"/>
310
+ </xsl:template>
311
+ <xsl:template match="/ubl:Invoice | /cn:CreditNote" priority="49" mode="d7e29">
312
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
313
+ <xsl:choose>
314
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
315
+ <schxslt:rule pattern="d7e29">
316
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "/ubl:Invoice | /cn:CreditNote" shadowed by preceding rule</xsl:comment>
317
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
318
+ <xsl:attribute name="context">/ubl:Invoice | /cn:CreditNote</xsl:attribute>
319
+ </svrl:suppressed-rule>
320
+ </schxslt:rule>
321
+ <xsl:next-match>
322
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
323
+ </xsl:next-match>
324
+ </xsl:when>
325
+ <xsl:otherwise>
326
+ <schxslt:rule pattern="d7e29">
327
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
328
+ <xsl:attribute name="context">/ubl:Invoice | /cn:CreditNote</xsl:attribute>
329
+ </svrl:fired-rule>
330
+ <xsl:if test="exists(cac:OrderReference/cbc:ID) and string-length(cac:OrderReference/cbc:ID) &gt; 127">
331
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C3">
332
+ <xsl:attribute name="test">exists(cac:OrderReference/cbc:ID) and string-length(cac:OrderReference/cbc:ID) &gt; 127</xsl:attribute>
333
+ <svrl:text>[BR-KSA-F-06-C3] - Field character limits for Purchase order ID field (BT-13) have not been met. The maximum limit is 127 characters.</svrl:text>
334
+ <svrl:message-code>BR-KSA-F-06-C3</svrl:message-code>
335
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
336
+ </svrl:failed-assert>
337
+ </xsl:if>
338
+ <xsl:if test="exists(cac:ContractDocumentReference/cbc:ID) and string-length(cac:ContractDocumentReference/cbc:ID) &gt; 127">
339
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C5">
340
+ <xsl:attribute name="test">exists(cac:ContractDocumentReference/cbc:ID) and string-length(cac:ContractDocumentReference/cbc:ID) &gt; 127</xsl:attribute>
341
+ <svrl:text>[BR-KSA-F-06-C5] - Field character limits for Contract ID field (BT-12) have not been met. The maximum limit is 127 characters .</svrl:text>
342
+ <svrl:message-code>BR-KSA-F-06-C5</svrl:message-code>
343
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
344
+ </svrl:failed-assert>
345
+ </xsl:if>
346
+ <xsl:if test="not(exists(cbc:UUID) and (cbc:UUID) != '' and matches(cbc:UUID, '^[\w.-]+'))">
347
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-03">
348
+ <xsl:attribute name="test">exists(cbc:UUID) and (cbc:UUID) != '' and matches(cbc:UUID, '^[\w.-]+')</xsl:attribute>
349
+ <svrl:text>[BR-KSA-03]-The invoice must contain a unique identifier ("UUID") (KSA-1) given by the unit that issued the document (unique message identifier for interchange process). This value must contain only letters, digits, and dashes.</svrl:text>
350
+ <svrl:message-code>BR-KSA-03</svrl:message-code>
351
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
352
+ </svrl:failed-assert>
353
+ </xsl:if>
354
+ <xsl:if test="boolean(//*[matches(@name, '02\d{5}')])">
355
+ <xsl:if test="not((cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'QR'] and exists(cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'QR']/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) and (cac:AdditionalDocumentReference/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) != '' and (cac:AdditionalDocumentReference/cac:Attachment/cbc:EmbeddedDocumentBinaryObject[normalize-space(@mimeCode) = 'text/plain'])))">
356
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-27">
357
+ <xsl:attribute name="test">(cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'QR'] and exists(cac:AdditionalDocumentReference/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) and (cac:AdditionalDocumentReference/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) != '' and (cac:AdditionalDocumentReference/cac:Attachment/cbc:EmbeddedDocumentBinaryObject[normalize-space(@mimeCode) = 'text/plain']))</xsl:attribute>
358
+ <svrl:text>[BR-KSA-27]-The document must contain aa QR code (KSA-14), and this code must be base64Binary.
359
+ Please refer to the Security Features Implementation Standards for more details.</svrl:text>
360
+ <svrl:message-code>BR-KSA-27</svrl:message-code>
361
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
362
+ </svrl:failed-assert>
363
+ </xsl:if>
364
+ </xsl:if>
365
+ <xsl:if test="exists(cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'QR']/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) and (string-length(cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'QR']/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) &gt; 700 or string-length(cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'QR']/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) &lt; 1)">
366
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-CL-KSA-14">
367
+ <xsl:attribute name="test">exists(cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'QR']/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) and (string-length(cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'QR']/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) &gt; 700 or string-length(cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'QR']/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) &lt; 1)</xsl:attribute>
368
+ <svrl:text>[KSA-14]-Field character limits for QR field have not been met. The minimum limit is 1 and the maximum limit is 700.</svrl:text>
369
+ <svrl:message-code>BR-CL-KSA-14</svrl:message-code>
370
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
371
+ </svrl:failed-assert>
372
+ </xsl:if>
373
+ <xsl:if test="not((cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'ICV'] and (cac:AdditionalDocumentReference/cbc:UUID) != ''))">
374
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-33">
375
+ <xsl:attribute name="test">(cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'ICV'] and (cac:AdditionalDocumentReference/cbc:UUID) != '')</xsl:attribute>
376
+ <svrl:text>[BR-KSA-33]-Each invoice must have an invoice counter value (KSA-16).</svrl:text>
377
+ <svrl:message-code>BR-KSA-33</svrl:message-code>
378
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
379
+ </svrl:failed-assert>
380
+ </xsl:if>
381
+ <xsl:if test="not(matches(cac:AdditionalDocumentReference/cbc:UUID, '^[0-9]*$'))">
382
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-34">
383
+ <xsl:attribute name="test">matches(cac:AdditionalDocumentReference/cbc:UUID, '^[0-9]*$')</xsl:attribute>
384
+ <svrl:text>[BR-KSA-34]-The invoice counter value (KSA-16) contains only digits.</svrl:text>
385
+ <svrl:message-code>BR-KSA-34</svrl:message-code>
386
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
387
+ </svrl:failed-assert>
388
+ </xsl:if>
389
+ <xsl:if test="(( (cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID) != ''
390
+ and (cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID) != ''
391
+ and (cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID) = (cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID) ))">
392
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-CUSTOM-VALIDATION-01">
393
+ <xsl:attribute name="test">(( (cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID) != ''
394
+ and (cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID) != ''
395
+ and (cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID) = (cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID) ))</xsl:attribute>
396
+ <svrl:text>[BR-CUSTOM-VALIDATION-01]- The Seller VAT registration number or seller group VAT registration number (BT-31) of The invoice must not match the buyer VAT registration number (BT-48) .</svrl:text>
397
+ <svrl:message-code>BR-CUSTOM-VALIDATION-01</svrl:message-code>
398
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
399
+ </svrl:failed-assert>
400
+ </xsl:if>
401
+ <xsl:if test="not(((cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID) != '' and (cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme[normalize-space(cbc:ID) = 'VAT'])))">
402
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-39">
403
+ <xsl:attribute name="test">not(((cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID) != '' and (cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme[normalize-space(cbc:ID) = 'VAT'])))</xsl:attribute>
404
+ <svrl:text>[BR-KSA-39]-The invoice must contain the seller VAT registration number or seller group VAT registration number (BT-31).</svrl:text>
405
+ <svrl:message-code>BR-KSA-39</svrl:message-code>
406
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
407
+ </svrl:failed-assert>
408
+ </xsl:if>
409
+ <xsl:if test="not((cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'PIH'] and exists(cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'PIH']/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) and (cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'PIH']/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) != '' and (cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'PIH']/cac:Attachment/cbc:EmbeddedDocumentBinaryObject[normalize-space(@mimeCode) = 'text/plain'])))">
410
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-61">
411
+ <xsl:attribute name="test">(cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'PIH'] and exists(cac:AdditionalDocumentReference/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) and (cac:AdditionalDocumentReference/cac:Attachment/cbc:EmbeddedDocumentBinaryObject) != '' and (cac:AdditionalDocumentReference/cac:Attachment/cbc:EmbeddedDocumentBinaryObject[normalize-space(@mimeCode) = 'text/plain']))</xsl:attribute>
412
+ <svrl:text>[BR-KSA-61]-Previous invoice hash (KSA-13) must exist in an invoice.</svrl:text>
413
+ <svrl:message-code>BR-KSA-61</svrl:message-code>
414
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
415
+ </svrl:failed-assert>
416
+ </xsl:if>
417
+ <xsl:if test="not(exists(cbc:TaxCurrencyCode) and (cbc:TaxCurrencyCode) != '')">
418
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-68">
419
+ <xsl:attribute name="test">exists(cbc:TaxCurrencyCode) and (cbc:TaxCurrencyCode) != ''</xsl:attribute>
420
+ <svrl:text>[BR-KSA-68]-Tax currency code (BT-6) must exist in an invoice.</svrl:text>
421
+ <svrl:message-code>BR-KSA-68</svrl:message-code>
422
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
423
+ </svrl:failed-assert>
424
+ </xsl:if>
425
+ <xsl:for-each select="//cac:AllowanceCharge[cbc:ChargeIndicator=true() and not(parent::cac:Price)]">
426
+ <xsl:if test="not(contains( ' AA AAA AAC AAD AAE AAF AAH AAI AAS AAT AAV AAY AAZ ABA ABB ABC ABD ABF ABK ABL ABN ABR ABS ABT ABU ACF ACG ACH ACI ACJ ACK ACL ACM ACS ADC ADE ADJ ADK ADL ADM ADN ADO ADP ADQ ADR ADT ADW ADY ADZ AEA AEB AEC AED AEF AEH AEI AEJ AEK AEL AEM AEN AEO AEP AES AET AEU AEV AEW AEX AEY AEZ AJ AU CA CAB CAD CAE CAF CAI CAJ CAK CAL CAM CAN CAO CAPCAQ CAR CAS CAT CAU CAV CAW CD CG CS CT DAB DAD DL EG EP ER FAA FAB FAC FC FH FI GAA HAA HD HH IAA AB ID IF IR IS KO L1 LA LAA LAB LF MAE MI ML NAA OA PA PAA PC PL RAB RAC RAD RAF RE RF RH RV SA SAA SAD SAE SAI SG SH SM SU TAB AC TT TV V1 V2 WH XAA YY ZZZ ', cbc:AllowanceChargeReasonCode))">
427
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-CL-06">
428
+ <xsl:attribute name="test">cac:Price/cac:AllowanceCharge[cbc:ChargeIndicator = true()] and (cac:Price/cac:AllowanceCharge[cbc:AllowanceChargeReasonCode = /ubl:Invoice/cac:AllowanceCharge/cbc:AllowanceChargeReasonCode] )</xsl:attribute>
429
+ <svrl:text>[BR-KSA-CL-06]-Code for the reason for document level charge (BT-105) and the code for the reason for invoice line charge (BT-145) MUST be coded using UNTDID 7161 code list. https://unece.org/fileadmin/DAM/trade/untdid/d16b/tred/tred7161.htm</svrl:text>
430
+ <svrl:message-code>BR-KSA-CL-06</svrl:message-code>
431
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
432
+ </svrl:failed-assert>
433
+ </xsl:if>
434
+ \
435
+ </xsl:for-each>
436
+ <xsl:if test="not(exists(cbc:IssueTime) and (cbc:IssueTime) != '' and (matches(cbc:IssueTime, '^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$') or matches(cbc:IssueTime, '^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])Z$')))">
437
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-70">
438
+ <xsl:attribute name="test">exists(cbc:IssueTime) and (cbc:IssueTime) != '' and (matches(cbc:IssueTime,
439
+ '^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$') or matches(cbc:IssueTime,
440
+ '^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])Z$'))</xsl:attribute>
441
+ <svrl:text>[BR-KSA-70]-The invoice must contain Invoice Issue Time (KSA-25). This value should be in the format: hh:mm:ss for time expressed in local time (eg 19:20:30) or hh:mm:ssZ for time expressed in UTC (eg 19:20:30Z).</svrl:text>
442
+ <svrl:message-code>BR-KSA-70</svrl:message-code>
443
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
444
+ </svrl:failed-assert>
445
+ </xsl:if>
446
+ </schxslt:rule>
447
+ <xsl:next-match>
448
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
449
+ </xsl:next-match>
450
+ </xsl:otherwise>
451
+ </xsl:choose>
452
+ </xsl:template>
453
+ <xsl:template match="/ubl:Invoice/cac:LegalMonetaryTotal[exists(cbc:PrepaidAmount)]/cac:InvoiceLine" priority="49" mode="d7e29">
454
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
455
+ <xsl:choose>
456
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
457
+ <schxslt:rule pattern="d7e29">
458
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:LegalMonetaryTotal" shadowed by preceding rule</xsl:comment>
459
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
460
+ <xsl:attribute name="context">cac:LegalMonetaryTotal </xsl:attribute>
461
+ </svrl:suppressed-rule>
462
+ </schxslt:rule>
463
+ <xsl:next-match>
464
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
465
+ </xsl:next-match>
466
+ </xsl:when>
467
+ <xsl:otherwise>
468
+ <schxslt:rule pattern="d7e29">
469
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
470
+ <xsl:attribute name="context">cac:LegalMonetaryTotal </xsl:attribute>
471
+ </svrl:fired-rule>
472
+ </schxslt:rule>
473
+ <xsl:next-match>
474
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
475
+ </xsl:next-match>
476
+ </xsl:otherwise>
477
+ </xsl:choose>
478
+ </xsl:template>
479
+ <xsl:template match="/ubl:Invoice[cac:LegalMonetaryTotal/cbc:PrepaidAmount &gt; 0]/cac:InvoiceLine" priority="49" mode="d7e29">
480
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
481
+ <xsl:choose>
482
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
483
+ <schxslt:rule pattern="d7e29">
484
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "/ubl:Invoice /cac:InvoiceLine/cac:DocumentReference/cbc:DocumentTypeCode" shadowed by preceding rule</xsl:comment>
485
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
486
+ <xsl:attribute name="context">/ubl:Invoice/cac:InvoiceLine/cac:DocumentReference/cbc:DocumentTypeCode</xsl:attribute>
487
+ </svrl:suppressed-rule>
488
+ </schxslt:rule>
489
+ <xsl:next-match>
490
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
491
+ </xsl:next-match>
492
+ </xsl:when>
493
+ <xsl:otherwise>
494
+ <schxslt:rule pattern="d7e29">
495
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
496
+ <xsl:attribute name="context">/ubl:Invoice/cac:InvoiceLine/cac:DocumentReference/cbc:DocumentTypeCode</xsl:attribute>
497
+ </svrl:fired-rule>
498
+ <xsl:for-each select="(./cac:DocumentReference)">
499
+ <!-- xsl:if test="not(normalize-space(./cbc:DocumentTypeCode)='386')">
500
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-74">
501
+ <xsl:attribute name="test">/ubl:Invoice/cac:InvoiceLine/cac:DocumentReference/cbc:DocumentTypeCode</xsl:attribute>
502
+ <svrl:text>[BR-KSA-74]-Prepayment Document Type Code (KSA-30) for the Invoice line document reference must be '386'.</svrl:text>
503
+ <svrl:message-code>BR-KSA-74</svrl:message-code>
504
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
505
+ </svrl:failed-assert>
506
+ </xsl:if -->
507
+ <xsl:choose>
508
+ <xsl:when test="(./cbc:DocumentTypeCode)!='386'">
509
+ <xsl:if test="not(normalize-space(./cbc:DocumentTypeCode)='386')">
510
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-74">
511
+ <xsl:attribute name="test">/ubl:Invoice/cac:InvoiceLine/cac:DocumentReference/cbc:DocumentTypeCode</xsl:attribute>
512
+ <svrl:text>[BR-KSA-74]-Prepayment Document Type Code (KSA-30) for the Invoice line document reference must be '386'.</svrl:text>
513
+ <svrl:message-code>BR-KSA-74</svrl:message-code>
514
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
515
+ </svrl:failed-assert>
516
+ </xsl:if>
517
+ </xsl:when>
518
+ <xsl:otherwise>
519
+ <xsl:if test="not( (../cbc:LineExtensionAmount)=0.00) or not((../cac:TaxTotal/cbc:TaxAmount)=0.00) or not((../cac:TaxTotal/cbc:RoundingAmount)=0) or not((../cac:Price/cbc:PriceAmount)=0.00) ">
520
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-82">
521
+ <xsl:attribute name="test">not( (../cbc:LineExtensionAmount)=0 and (../cac:TaxTotal/cbc:TaxAmount)=0 and (../cac:Price/cbc:PriceAmount)=0 ) </xsl:attribute>
522
+ <svrl:text>[BR-KSA-82]-An Invoice line (BG-25) where Prepayment Document Type Code (KSA-30) is provided, then Item net price (BT-146); Invoice line allowance amount (BT-136); Invoice line charge amount (BT-141); Item line net amount (BT-131); line VAT amount (KSA-11); and line amount with VAT (KSA-12) for that line shall be 0 (Zero), if exist. </svrl:text>
523
+ <svrl:message-code>BR-KSA-82</svrl:message-code>
524
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
525
+ </svrl:failed-assert>
526
+ </xsl:if>
527
+ <xsl:if test="exists(../cac:AllowanceCharge) ">
528
+ <xsl:if test="not ((../cac:AllowanceCharge/cbc:Amount)=0.00) ">
529
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-82">
530
+ <xsl:attribute name="test">not( (../cbc:LineExtensionAmount)=0 and (../cac:TaxTotal/cbc:TaxAmount)=0 and (../cac:Price/cbc:PriceAmount)=0 ) </xsl:attribute>
531
+ <svrl:text>[BR-KSA-82]-An Invoice line (BG-25) where Prepayment Document Type Code (KSA-30) is provided, then Item net price (BT-146); Invoice line allowance amount (BT-136); Invoice line charge amount (BT-141); Item line net amount (BT-131); line VAT amount (KSA-11); and line amount with VAT (KSA-12) for that line shall be 0 (Zero), if exist. </svrl:text>
532
+ <svrl:message-code>BR-KSA-82</svrl:message-code>
533
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
534
+ </svrl:failed-assert>
535
+ </xsl:if>
536
+ </xsl:if>
537
+ </xsl:otherwise>
538
+ </xsl:choose>
539
+ </xsl:for-each>
540
+ <!-- BR-KSA-73-->
541
+ <xsl:choose>
542
+ <xsl:when test="count(/ubl:Invoice/cac:InvoiceLine/cac:DocumentReference) &gt;0">
543
+ <xsl:for-each select="(./cac:DocumentReference)">
544
+ <xsl:if test="not(exists(./cbc:ID) and exists(./cbc:IssueDate) and exists(./cbc:IssueTime) and exists(./cbc:DocumentTypeCode) )">
545
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-73">
546
+ <xsl:attribute name="test">not(exists(/ubl:Invoice/cac:LegalMonetaryTotal/cbc:PrepaidAmount) and exists(cac:DocumentReference/cbc:ID) and exists(cac:DocumentReference/cbc:IssueDate) and exists(cac:DocumentReference/cbc:IssueTime) and exists(cac:DocumentReference/cbc:DocumentTypeCode) )</xsl:attribute>
547
+ <svrl:text>[BR-KSA-73]-If Pre-Paid amount (BT-113) is provided, then the following data is mandatory to provide as additional invoice line(s) -Prepayment ID (KSA-26) -Sequential invoice number (BT-1) of the prepayment invoice(s)-Prepayment Issue Date (KSA-28) -Issue date (BT-2) of the prepayment invoice(s) Prepayment Issue Time (KSA-29) - Issue time (KSA-25) of the prepayment invoice(s) Prepayment Document Type Code (KSA-30)- Invoice type code (BT-3) must be 386. </svrl:text>
548
+ <svrl:message-code>BR-KSA-73</svrl:message-code>
549
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
550
+ </svrl:failed-assert>
551
+ </xsl:if>
552
+ </xsl:for-each >
553
+ </xsl:when>
554
+ <xsl:otherwise>
555
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-73">
556
+ <xsl:attribute name="test">not(exists(/ubl:Invoice/cac:LegalMonetaryTotal/cbc:PrepaidAmount) and exists(cac:DocumentReference/cbc:ID) and exists(cac:DocumentReference/cbc:IssueDate) and exists(cac:DocumentReference/cbc:IssueTime) and exists(cac:DocumentReference/cbc:DocumentTypeCode) )</xsl:attribute>
557
+ <svrl:text>[BR-KSA-73]-If Pre-Paid amount (BT-113) is provided, then the following data is mandatory to provide as additional invoice line(s) -Prepayment ID (KSA-26) -Sequential invoice number (BT-1) of the prepayment invoice(s)-Prepayment Issue Date (KSA-28) -Issue date (BT-2) of the prepayment invoice(s) Prepayment Issue Time (KSA-29) - Issue time (KSA-25) of the prepayment invoice(s) Prepayment Document Type Code (KSA-30)- Invoice type code (BT-3) must be 386 </svrl:text>
558
+ <svrl:message-code>BR-KSA-73</svrl:message-code>
559
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
560
+ </svrl:failed-assert>
561
+ </xsl:otherwise>
562
+ </xsl:choose>
563
+ <!-- END BR-KSA-73-->
564
+
565
+ <!-- BR-KSA-75-->
566
+ <xsl:if test="count(/ubl:Invoice/cac:InvoiceLine/cac:DocumentReference) &gt;0">
567
+ <xsl:for-each select="(./cac:DocumentReference)">
568
+ <xsl:if test="not( exists(../cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount) and exists(../cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:Percent) and exists(../cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount) and exists(../cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:ID))">
569
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-75">
570
+ <xsl:attribute name="test">not(exists(/ubl:Invoice/cac:LegalMonetaryTotal/cbc:PrepaidAmount) and exists(cac:DocumentReference/cbc:ID) and exists(cac:DocumentReference/cbc:IssueDate) and exists(cac:DocumentReference/cbc:IssueTime) and exists(cac:DocumentReference/cbc:DocumentTypeCode) )</xsl:attribute>
571
+ <svrl:text>[BR-KSA-75]-If Prepayment Document Type code (KSA-30) is provided in an Invoice Line, then the following data is mandatory to provide in that invoice line - Prepayment VAT category Taxable Amount (KSA-31) - Sum total of taxable amounts subject to specific VAT Category code of the prepayment invoice(s); Prepayment VAT Category Tax Amount (KSA-32) - Sum total of tax amounts subject to specific VAT Category code of the prepayment invoice(s); Prepayment VAT category code (KSA-33) - the VAT category code of the associated Prepayment invoice(s); Prepayment VAT rate (KSA-34) - VAT rate of the specific VAT Category code of the prepayment invoice(s)</svrl:text>
572
+ <svrl:message-code>BR-KSA-75</svrl:message-code>
573
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
574
+ </svrl:failed-assert>
575
+ </xsl:if>
576
+ </xsl:for-each >
577
+ </xsl:if>
578
+ <!-- END BR-KSA-75-->
579
+ <xsl:for-each select="./cac:TaxTotal/cac:TaxSubtotal">
580
+ <xsl:choose>
581
+ <xsl:when test= " not (./cac:TaxCategory/normalize-space(cbc:ID)='S') and (./cac:TaxCategory/normalize-space(cbc:ID)='O' and not(exists(./cac:TaxCategory/cbc:Percent)) or ./cac:TaxCategory/normalize-space(cbc:ID)='E' or ./cac:TaxCategory/normalize-space(cbc:ID)='Z' or normalize-space(./cac:TaxCategory/cbc:Percent)='')">
582
+ <xsl:if test="not(format-number(./cbc:TaxAmount,'#.00') = format-number(( round((((xs:decimal(./cbc:TaxableAmount) * (0)) div 100) * 100 + 0.01)) div 100), '#.00') )">
583
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-79">
584
+ <xsl:attribute name="test">/ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount</xsl:attribute>
585
+ <svrl:text>[BR-KSA-79]-The Prepayment VAT Category Tax Amount (KSA-32) must be Prepayment VAT category Taxable Amount( (KSA-31) x Prepayment VAT rate (KSA-34) /100).</svrl:text>
586
+ <svrl:message-code>BR-KSA-79</svrl:message-code>
587
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
588
+ </svrl:failed-assert>
589
+ </xsl:if>
590
+ </xsl:when>
591
+ <xsl:otherwise>
592
+ <xsl:if test=" normalize-space(./cac:TaxCategory/cbc:Percent)='' or not( format-number(./cbc:TaxAmount,'#.00') = (format-number((( round((((./cbc:TaxableAmount * (./cac:TaxCategory[cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT']/xs:decimal(cbc:Percent) )) div 100) * 100 + 0.01)) div 100)-0.01), '#.00')) or format-number(./cbc:TaxAmount,'#.00') = (format-number((( round((((./cbc:TaxableAmount * (./cac:TaxCategory[cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT']/xs:decimal(cbc:Percent) )) div 100) * 100 + 0.01)) div 100)+0.01), '#.00')) or format-number(./cbc:TaxAmount,'#.00') = (format-number((( round((((./cbc:TaxableAmount * (./cac:TaxCategory[cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT']/xs:decimal(cbc:Percent) )) div 100) * 100 + 0.01)) div 100)), '#.00')))">
593
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-79">
594
+ <xsl:attribute name="test">/ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount</xsl:attribute>
595
+ <svrl:text>[BR-KSA-79]-The Prepayment VAT Category Tax Amount (KSA-32) must be Prepayment VAT category Taxable Amount( (KSA-31) x Prepayment VAT rate (KSA-34) /100).</svrl:text>
596
+ <svrl:message-code>BR-KSA-79</svrl:message-code>
597
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
598
+ </svrl:failed-assert>
599
+ </xsl:if>
600
+ </xsl:otherwise>
601
+ </xsl:choose>
602
+
603
+ <xsl:if test="not( format-number(xs:decimal(/ubl:Invoice/cac:LegalMonetaryTotal/cbc:PrepaidAmount), '#.00') = format-number(xs:decimal(sum(/ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount))+ (sum(/ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount)),'#.00') )">
604
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-80">
605
+ <xsl:attribute name="test">cac:LegalMonetaryTotal </xsl:attribute>
606
+ <svrl:text>[BR-KSA-80]-If Pre-Paid amount (BT-113) is provided then the Pre-Paid amount (BT-113) must equal to the sum total of the Prepayment VAT category Taxable Amount (KSA-31) and Prepayment VAT Category Tax Amount (KSA-32).</svrl:text>
607
+ <svrl:message-code>BR-KSA-80</svrl:message-code>
608
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
609
+ </svrl:failed-assert>
610
+ </xsl:if>
611
+ <!-- BR-DEC-06-->
612
+ <xsl:if test="not(string-length(substring-after(cbc:TaxableAmount,'.')) &lt;= 2 and string-length(substring-after(cbc:TaxAmount,'.')) &lt;= 2)">
613
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-DEC-06">
614
+ <xsl:attribute name="test">string-length(substring-after(cac:TaxTotal/cbc:RoundingAmount,'.'))&lt;=2</xsl:attribute>
615
+ <svrl:text>[BR-KSA-DEC-06]-Prepayment VAT category Taxable Amount (KSA-31) and Prepayment VAT Category Tax Amount (KSA-32) must have a maximum two decimals.</svrl:text>
616
+ <svrl:message-code>BR-KSA-DEC-06</svrl:message-code>
617
+ <svrl:message-category> KSA - decimals rules (BR-KSA-DEC)</svrl:message-category>
618
+ </svrl:failed-assert>
619
+ </xsl:if>
620
+ <!-- END BR-DEC-06-->
621
+ <xsl:if test="cac:TaxCategory[normalize-space(cbc:ID)='Z'][ cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT'] and not(((xs:decimal(cac:TaxCategory/cbc:Percent))=0))">
622
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-76">
623
+ <xsl:attribute name="test">/ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cac:TaxCategory /cbc:Percent</xsl:attribute>
624
+ <svrl:text>[BR-KSA-76]-An Invoice line (BG-25) where the Prepayment VAT category code (KSA-33) is "Zero rated" the Prepayment VAT rate (KSA-34) shall be 0 (zero).</svrl:text>
625
+ <svrl:message-code>BR-KSA-76</svrl:message-code>
626
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
627
+ </svrl:failed-assert>
628
+ </xsl:if>
629
+ <xsl:if test="cac:TaxCategory[normalize-space(cbc:ID)='E'][cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT'] and not(((xs:decimal(cac:TaxCategory/cbc:Percent))=0))">
630
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-77">
631
+ <xsl:attribute name="test">/ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cac:TaxCategory /cbc:Percent</xsl:attribute>
632
+ <svrl:text>[BR-KSA-77]-An Invoice line (BG-25) where the Prepayment VAT category code (KSA-33) is "Exempt from VAT" the Prepayment VAT rate (KSA-34) shall be 0 (zero).</svrl:text>
633
+ <svrl:message-code>BR-KSA-77</svrl:message-code>
634
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
635
+ </svrl:failed-assert>
636
+ </xsl:if>
637
+ <xsl:if test="cac:TaxCategory[normalize-space(cbc:ID)='O'][cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT'] and not(((xs:decimal(cac:TaxCategory/cbc:Percent))=0))">
638
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-78">
639
+ <xsl:attribute name="test">/ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cac:TaxCategory /cbc:Percent</xsl:attribute>
640
+ <svrl:text>[BR-KSA-78]-An Invoice line (BG-25) where the Prepayment VAT category code (KSA-33) is "Not subject to VAT" the Prepayment VAT rate (KSA-34) shall be 0 (zero).</svrl:text>
641
+ <svrl:message-code>BR-KSA-78</svrl:message-code>
642
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
643
+ </svrl:failed-assert>
644
+ </xsl:if>
645
+ </xsl:for-each>
646
+ </schxslt:rule>
647
+ <xsl:next-match>
648
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
649
+ </xsl:next-match>
650
+ </xsl:otherwise>
651
+ </xsl:choose>
652
+ </xsl:template>
653
+ <!-- NEW BR-KSA-81 -->
654
+ <xsl:template match="cac:AccountingCustomerParty/cac:Party" priority="29" mode="d7e29">
655
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
656
+ <xsl:choose>
657
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e212']">
658
+ <schxslt:rule pattern="d7e212">
659
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID" shadowed by preceding rule</xsl:comment>
660
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
661
+ <xsl:attribute name="context">cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID</xsl:attribute>
662
+ </svrl:suppressed-rule>
663
+ </schxslt:rule>
664
+ <xsl:next-match>
665
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
666
+ </xsl:next-match>
667
+ </xsl:when>
668
+ <xsl:otherwise>
669
+ <schxslt:rule pattern="d7e212">
670
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
671
+ <xsl:attribute name="context">cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID</xsl:attribute>
672
+ </svrl:fired-rule>
673
+ <xsl:if test="boolean(//*[matches(@name, '01\d{5}')])">
674
+ <xsl:if test="not(exists(./cac:PartyTaxScheme/ cbc:CompanyID))">
675
+ <xsl:if test="not(exists(./cac:PartyIdentification/cbc:ID) and normalize-space(./cac:PartyIdentification/cbc:ID) !='' )">
676
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-81">
677
+ <xsl:attribute name="test">cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID</xsl:attribute>
678
+ <svrl:text>[BR-KSA-81]-The other Buyer ID (BT-46) must present in the tax invoice and associated debit notes and credit notes (KSA-2, position 1 and 2 = 01), where the buyer VAT registration number or buyer group VAT registration number (BT-48) is not provided.</svrl:text>
679
+ <svrl:message-code>BR-KSA-81</svrl:message-code>
680
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
681
+ </svrl:failed-assert>
682
+ </xsl:if>
683
+ </xsl:if>
684
+ </xsl:if>
685
+ </schxslt:rule>
686
+ <xsl:next-match>
687
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e194')"/>
688
+ </xsl:next-match>
689
+ </xsl:otherwise>
690
+ </xsl:choose>
691
+ </xsl:template>
692
+ <!-- END BR-KSA-81 -->
693
+ <xsl:template match="cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[cbc:TaxExemptionReasonCode = 'VATEX-SA-EDU'] | cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[cbc:TaxExemptionReasonCode = 'VATEX-SA-HEA']" priority="48" mode="d7e29">
694
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
695
+ <xsl:choose>
696
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
697
+ <schxslt:rule pattern="d7e29">
698
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[cbc:TaxExemptionReasonCode = 'VATEX-SA-EDU'] | cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[cbc:TaxExemptionReasonCode = 'VATEX-SA-HEA']" shadowed by preceding rule</xsl:comment>
699
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
700
+ <xsl:attribute name="context">cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[cbc:TaxExemptionReasonCode = 'VATEX-SA-EDU'] | cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[cbc:TaxExemptionReasonCode = 'VATEX-SA-HEA']</xsl:attribute>
701
+ </svrl:suppressed-rule>
702
+ </schxslt:rule>
703
+ <xsl:next-match>
704
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
705
+ </xsl:next-match>
706
+ </xsl:when>
707
+ <xsl:otherwise>
708
+ <schxslt:rule pattern="d7e29">
709
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
710
+ <xsl:attribute name="context">cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[cbc:TaxExemptionReasonCode = 'VATEX-SA-EDU'] | cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[cbc:TaxExemptionReasonCode = 'VATEX-SA-HEA']</xsl:attribute>
711
+ </svrl:fired-rule>
712
+ <xsl:if test="not(exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID) and (//cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID/@schemeID) = 'NAT')">
713
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-49">
714
+ <xsl:attribute name="test">exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID) and (//cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID/@schemeID) = 'NAT'</xsl:attribute>
715
+ <svrl:text>[BR-KSA-49]-If the tax exemption reason code (BT-121) is equal to VATEX-SA-EDU or VATEX-SA-HEA, then the other buyer ID (BT-46) is mandatory and must be national ID (BT-46-1 = NAT).</svrl:text>
716
+ <svrl:message-code>BR-KSA-49</svrl:message-code>
717
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
718
+ </svrl:failed-assert>
719
+ </xsl:if>
720
+ </schxslt:rule>
721
+ <xsl:next-match>
722
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
723
+ </xsl:next-match>
724
+ </xsl:otherwise>
725
+ </xsl:choose>
726
+ </xsl:template>
727
+ <xsl:template match="cbc:IssueDate" priority="47" mode="d7e29">
728
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
729
+ <xsl:choose>
730
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
731
+ <schxslt:rule pattern="d7e29">
732
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cbc:IssueDate" shadowed by preceding rule</xsl:comment>
733
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
734
+ <xsl:attribute name="context">cbc:IssueDate</xsl:attribute>
735
+ </svrl:suppressed-rule>
736
+ </schxslt:rule>
737
+ <xsl:next-match>
738
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
739
+ </xsl:next-match>
740
+ </xsl:when>
741
+ <xsl:otherwise>
742
+ <schxslt:rule pattern="d7e29">
743
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
744
+ <xsl:attribute name="context">cbc:IssueDate</xsl:attribute>
745
+ </svrl:fired-rule>
746
+ <xsl:if test="not(xs:date(.) &lt;= current-date())">
747
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-04">
748
+ <xsl:attribute name="test">xs:date(.) &lt;= current-date()</xsl:attribute>
749
+ <svrl:text>[BR-KSA-04]-The document issue date (BT-2) must be less or equal to the current date.</svrl:text>
750
+ <svrl:message-code>BR-KSA-04</svrl:message-code>
751
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
752
+ </svrl:failed-assert>
753
+ </xsl:if>
754
+ </schxslt:rule>
755
+ <xsl:next-match>
756
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
757
+ </xsl:next-match>
758
+ </xsl:otherwise>
759
+ </xsl:choose>
760
+ </xsl:template>
761
+ <xsl:template match="cbc:InvoiceTypeCode" priority="46" mode="d7e29">
762
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
763
+ <xsl:choose>
764
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
765
+ <schxslt:rule pattern="d7e29">
766
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">error: Rule for context "cbc:InvoiceTypeCode" shadowed by preceding rule</xsl:comment>
767
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
768
+ <xsl:attribute name="context">cbc:InvoiceTypeCode</xsl:attribute>
769
+ </svrl:suppressed-rule>
770
+ </schxslt:rule>
771
+ <xsl:next-match>
772
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
773
+ </xsl:next-match>
774
+ </xsl:when>
775
+ <xsl:otherwise>
776
+ <schxslt:rule pattern="d7e29">
777
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
778
+ <xsl:attribute name="context">cbc:InvoiceTypeCode</xsl:attribute>
779
+ </svrl:fired-rule>
780
+ <xsl:if test="not(not(contains(normalize-space(.), ' ')) and contains(' 388 383 381 386 ', concat(' ', normalize-space(.), ' ')))">
781
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-05">
782
+ <xsl:attribute name="test">not(contains(normalize-space(.), ' ')) and contains(' 388 383 381 ', concat(' ', normalize-space(.), ' '))</xsl:attribute>
783
+ <svrl:text>[BR-KSA-05]-The invoice type code (BT-3) must be equal to one of value from the subset of UN/CEFACT code list 1001, D.16B agreed for KSA electronic invoices. Please refer paragraph 11.2.1 of XML implementation Standards.</svrl:text>
784
+ <svrl:message-code>BR-KSA-05</svrl:message-code>
785
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
786
+ </svrl:failed-assert>
787
+ </xsl:if>
788
+ <xsl:if test="not(((string-length(@name))= 7) and ((substring(@name,1,2) = '01') or (substring(@name,1,2) = '02')) and ((substring(@name,3,1) = '0') or (substring(@name,3,1) = '1')) and ((substring(@name,4,1) = '0') or (substring(@name,4,1) = '1')) and ((substring(@name,5,1) = '0') or (substring(@name,5,1) = '1')) and ((substring(@name,6,1) = '0') or (substring(@name,6,1) = '1')) and ((substring(@name,7,1) = '0') or (substring(@name,7,1) = '1')))">
789
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-06">
790
+ <xsl:attribute name="test">((string-length(@name))= 7) and ((substring(@name,1,2) = '01') or (substring(@name,1,2) = '02')) and ((substring(@name,3,1) = '0') or (substring(@name,3,1) = '1')) and ((substring(@name,4,1) = '0') or (substring(@name,4,1) = '1')) and ((substring(@name,5,1) = '0') or (substring(@name,5,1) = '1')) and ((substring(@name,6,1) = '0') or (substring(@name,6,1) = '1')) and ((substring(@name,7,1) = '0') or (substring(@name,7,1) = '1'))</xsl:attribute>
791
+ <svrl:text>[BR-KSA-06]-The invoice transaction code (KSA-2) must exist and respect the following structure:
792
+ NNPNESB
793
+ where
794
+ NN (positions 1 and 2) = invoice subtype:
795
+ - 01 for tax invoice
796
+ - 02 for simplified tax invoice
797
+ P (position 3) = 3rd Party invoice transaction, 0 for false, 1 for true
798
+ N (position 4) = Nominal invoice transaction, 0 for false, 1 for true
799
+ E (position 5) = Exports invoice transaction, 0 for false, 1 for true
800
+ S (position 6) = Summary invoice transaction, 0 for false, 1 for true
801
+ B (position 7) = Self billed invoice
802
+ </svrl:text>
803
+ <svrl:message-code>BR-KSA-06</svrl:message-code>
804
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
805
+ </svrl:failed-assert>
806
+ </xsl:if>
807
+ </schxslt:rule>
808
+ <xsl:next-match>
809
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
810
+ </xsl:next-match>
811
+ </xsl:otherwise>
812
+ </xsl:choose>
813
+ </xsl:template>
814
+ <xsl:template match="cac:AccountingSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID" priority="45" mode="d7e29">
815
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
816
+ <xsl:choose>
817
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
818
+ <schxslt:rule pattern="d7e29">
819
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">error: Rule for context "cac:AccountingSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID" shadowed by preceding rule</xsl:comment>
820
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
821
+ <xsl:attribute name="context">cac:AccountingSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID</xsl:attribute>
822
+ </svrl:suppressed-rule>
823
+ </schxslt:rule>
824
+ <xsl:next-match>
825
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
826
+ </xsl:next-match>
827
+ </xsl:when>
828
+ <xsl:otherwise>
829
+ <schxslt:rule pattern="d7e29">
830
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
831
+ <xsl:attribute name="context">cac:AccountingSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID</xsl:attribute>
832
+ </svrl:fired-rule>
833
+ <xsl:if test="not( string-length(normalize-space(./@schemeID)) &gt; 2 and contains(' CRN MOM MLS SAG OTH 700 ', ./@schemeID) and (matches((.), '^[a-zA-Z0-9]*$')))">
834
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-08">
835
+ <xsl:attribute name="test"> string-length(normalize-space(./@schemeID)) &gt; 2 and contains(' CRN MOM MLS SAG OTH 700 ', ./@schemeID) and (matches((.), '^[a-zA-Z0-9]*$'))</xsl:attribute>
836
+ <svrl:text>[BR-KSA-08]-The seller identification (BT-29) must exist only once with one of the scheme ID (BT-29-1) (CRN, MOM, MLS, SAG, OTH, 700) and must contain only alphanumeric characters. Commercial Registration number with "CRN" as schemeID ;MOMRAH license with "MOM" as schemeID ;MHRSD license with "MLS" as schemeID ;700 Number with "700" as schemeID ;MISA license with "SAG" as schemeID ;Other OD with "OTH" as schemeID. ;In case of multiple commercial registrations, the seller should fill the commercial registration of the branch in respect of which the Tax Invoice is being issued. In case multiple IDs exist then one of the above must be entered following the sequence specified above.</svrl:text>
837
+ <svrl:message-code>BR-KSA-08</svrl:message-code>
838
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
839
+ </svrl:failed-assert>
840
+ </xsl:if>
841
+ </schxslt:rule>
842
+ <xsl:next-match>
843
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
844
+ </xsl:next-match>
845
+ </xsl:otherwise>
846
+ </xsl:choose>
847
+ </xsl:template>
848
+ <xsl:template match="cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID" priority="44" mode="d7e29">
849
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
850
+ <xsl:choose>
851
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
852
+ <schxslt:rule pattern="d7e29">
853
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">error: Rule for context "cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID" shadowed by preceding rule</xsl:comment>
854
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
855
+ <xsl:attribute name="context">cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID</xsl:attribute>
856
+ </svrl:suppressed-rule>
857
+ </schxslt:rule>
858
+ <xsl:next-match>
859
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
860
+ </xsl:next-match>
861
+ </xsl:when>
862
+ <xsl:otherwise>
863
+ <schxslt:rule pattern="d7e29">
864
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
865
+ <xsl:attribute name="context">cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID</xsl:attribute>
866
+ </svrl:fired-rule>
867
+ <xsl:if test="not( string-length(normalize-space( ./@schemeID)) &gt; 2 and contains('TIN NAT IQA PAS CRN MOM MLS 700 SAG GCC OTH', ./@schemeID) and (matches((.), '^[a-zA-Z0-9]*$')) )">
868
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-14">
869
+ <xsl:attribute name="test">contains(' NAT TIN IQA PAS CRN MOM MLS SAG GCC OTH 700', ./@schemeID) and (matches((.), '^[a-zA-Z0-9]*$'))</xsl:attribute>
870
+ <svrl:text>[BR-KSA-14]-The buyer identification (BT-46), required only if buyer is not VAT registered, then the buyer identification (BT-46) must be provided with one of the scheme IDs (BT-46-1) (TIN, CRN, MOM, MLS, 700, SAG, NAT, GCC, IQA, OTH) and must contain only alphanumeric characters. Tax Identification Number "TIN" as schemeID ;Commercial registration number with "CRN" as schemeID ;MOMRAH license with "MOM" as schemeID ;MHRSD license with "MLS" as schemeID ;700 Number with "700" as schemeID ;MISA license with "SAG" as schemeID ;National ID with "NAT" as schemeID ;GCC ID with "GCC" as schemeID ;Iqama Number with "IQA" as schemeID ;Passport ID with "PAS" as schemeID ;Other ID with "OTH" as schemeID. ;In case of multiple commercial registrations, the seller should fill the commercial registration of the branch in respect of which the Tax Invoice is being issued. In case multiple IDs exist then one of the above must be entered following the sequence specified above</svrl:text>
871
+ <svrl:message-code>BR-KSA-14</svrl:message-code>
872
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
873
+ </svrl:failed-assert>
874
+ </xsl:if>
875
+ </schxslt:rule>
876
+ <xsl:next-match>
877
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
878
+ </xsl:next-match>
879
+ </xsl:otherwise>
880
+ </xsl:choose>
881
+ </xsl:template>
882
+ <xsl:template match="cac:AccountingSupplierParty/cac:Party/cac:PostalAddress" priority="43" mode="d7e29">
883
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
884
+ <xsl:choose>
885
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
886
+ <schxslt:rule pattern="d7e29">
887
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">error: Rule for context "cac:AccountingSupplierParty/cac:Party/cac:PostalAddress" shadowed by preceding rule</xsl:comment>
888
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
889
+ <xsl:attribute name="context">cac:AccountingSupplierParty/cac:Party/cac:PostalAddress</xsl:attribute>
890
+ </svrl:suppressed-rule>
891
+ </schxslt:rule>
892
+ <xsl:next-match>
893
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
894
+ </xsl:next-match>
895
+ </xsl:when>
896
+ <xsl:otherwise>
897
+ <schxslt:rule pattern="d7e29">
898
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
899
+ <xsl:attribute name="context">cac:AccountingSupplierParty/cac:Party/cac:PostalAddress</xsl:attribute>
900
+ </svrl:fired-rule>
901
+ <xsl:if test="exists(cbc:StreetName)">
902
+ <xsl:if test=" (string-length(cbc:StreetName) &gt; 1000 or string-length(cbc:StreetName) &lt; 1)">
903
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C4">
904
+ <xsl:attribute name="test">exists(cbc:StreetName) and (string-length(cbc:StreetName) &gt; 127 or string-length(cbc:StreetName) &lt; 1)</xsl:attribute>
905
+ <svrl:text>[BR-KSA-F-06-C4] - Field character limits for the Seller Address - Street field (BT-35) have not been met. The minimum limit is 1 character and the maximum limit is 1000 characters.</svrl:text>
906
+ <svrl:message-code>BR-KSA-F-06-C4</svrl:message-code>
907
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
908
+ </svrl:failed-assert>
909
+ </xsl:if>
910
+ </xsl:if>
911
+
912
+ <xsl:if test="not(exists(cbc:StreetName) and exists(cbc:BuildingNumber) and exists(cbc:CityName) and exists(cbc:PostalZone) and exists(cbc:CitySubdivisionName) and exists(cac:Country/cbc:IdentificationCode))">
913
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-09">
914
+ <xsl:attribute name="test">exists(cbc:StreetName) and exists(cbc:BuildingNumber) and exists(cbc:PlotIdentification) and exists(cbc:CityName) and exists(cbc:PostalZone) and exists(cbc:CitySubdivisionName) and exists(cac:Country/cbc:IdentificationCode)</xsl:attribute>
915
+ <svrl:text>[BR-KSA-09]-Seller address must contain street name (BT-35), building number (KSA-17), postal code (BT-38), city (BT-37), district (KSA-3), country code (BT-40). For more information please access this link: https://splonline.com.sa/en/national-address-1/</svrl:text>
916
+ <svrl:message-code>BR-KSA-09</svrl:message-code>
917
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
918
+ </svrl:failed-assert>
919
+ </xsl:if>
920
+ <xsl:if test="exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:AdditionalStreetName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:AdditionalStreetName) &gt; 127">
921
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C11">
922
+ <xsl:attribute name="test">
923
+ exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:AdditionalStreetName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:AdditionalStreetName) &gt; 127
924
+ </xsl:attribute>
925
+ <svrl:text>[BR-KSA-F-06-C11] - Field character limits for the Buyer Address - Additional street field (BT-51) have not been met. The maximum limit is 127 characters.
926
+ </svrl:text>
927
+ <svrl:message-code>BR-KSA-F-06-C11</svrl:message-code>
928
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
929
+ </svrl:failed-assert>
930
+ </xsl:if>
931
+ <xsl:if test="exists(cbc:CityName) and (string-length(cbc:CityName) &gt; 127 or string-length(cbc:CityName) &lt; 1)">
932
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C7">
933
+ <xsl:attribute name="test">
934
+ exists(cbc:CityName) and string-length(cbc:CityName) &gt; 127
935
+ </xsl:attribute>
936
+ <svrl:text>[BR-KSA-F-06-C7] - Field character limits for the Seller Address - City field (BT-37) have not been met. The minimum limit is 1 character and the maximum limit is 127 characters.
937
+ </svrl:text>
938
+ <svrl:message-code>BR-KSA-F-06-C7</svrl:message-code>
939
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
940
+ </svrl:failed-assert>
941
+ </xsl:if>
942
+ <xsl:if test="exists(cbc:AdditionalStreetName) and string-length(cbc:AdditionalStreetName) &gt; 127">
943
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C6">
944
+ <xsl:attribute name="test">exists(cbc:AdditionalStreetName) and string-length(cbc:AdditionalStreetName) &gt; 127</xsl:attribute>
945
+ <svrl:text>[BR-KSA-F-06-C6] - Field character limits for the Seller Address - Additional street field (BT-36) have not been met. The maximum limit is 127 characters.</svrl:text>
946
+ <svrl:message-code>BR-KSA-F-06-C6</svrl:message-code>
947
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
948
+ </svrl:failed-assert>
949
+ </xsl:if>
950
+ <xsl:if test="not(exists(cbc:PostalZone) and matches(cbc:PostalZone, '^[0-9]{5}$'))">
951
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-66">
952
+ <xsl:attribute name="test">exists(cbc:PostalZone) and matches(cbc:PostalZone, '^[0-9]{5}$')</xsl:attribute>
953
+ <svrl:text>[BR-KSA-66]-Seller postal code (BT-38) must be 5 digits.</svrl:text>
954
+ <svrl:message-code>BR-KSA-66</svrl:message-code>
955
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
956
+ </svrl:failed-assert>
957
+ </xsl:if>
958
+ </schxslt:rule>
959
+ <xsl:next-match>
960
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
961
+ </xsl:next-match>
962
+ </xsl:otherwise>
963
+ </xsl:choose>
964
+ </xsl:template>
965
+ <xsl:template match="cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'PIH']/cac:Attachment" priority="41" mode="d7e29">
966
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
967
+ <xsl:choose>
968
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
969
+ <schxslt:rule pattern="d7e29">
970
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'PIH']/cac:Attachment" shadowed by preceding rule</xsl:comment>
971
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
972
+ <xsl:attribute name="context">cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'PIH']/cac:Attachment</xsl:attribute>
973
+ </svrl:suppressed-rule>
974
+ </schxslt:rule>
975
+ <xsl:next-match>
976
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
977
+ </xsl:next-match>
978
+ </xsl:when>
979
+ <xsl:otherwise>
980
+ <schxslt:rule pattern="d7e29">
981
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
982
+ <xsl:attribute name="context">cac:AdditionalDocumentReference[normalize-space(cbc:ID) = 'PIH']/cac:Attachment</xsl:attribute>
983
+ </svrl:fired-rule>
984
+ <xsl:if test="not(exists(cbc:EmbeddedDocumentBinaryObject) and (cbc:EmbeddedDocumentBinaryObject) != '' and (cbc:EmbeddedDocumentBinaryObject[normalize-space(@mimeCode) = 'text/plain']))">
985
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-26">
986
+ <xsl:attribute name="test">exists(cbc:EmbeddedDocumentBinaryObject) and (cbc:EmbeddedDocumentBinaryObject) != '' and (cbc:EmbeddedDocumentBinaryObject[normalize-space(@mimeCode) = 'text/plain'])</xsl:attribute>
987
+ <svrl:text>[BR-KSA-26]-If the invoiceinvoice contains the previous invoice hash (KSA-13), this hashmust be base64 encoded SHA256.
988
+ This hash will be computed from all the elements of the previous invoice:
989
+ - UBL invoice
990
+ - hash of the previous invoice (of the previous invoice)
991
+ - QR code
992
+ - cryptographic stamp</svrl:text>
993
+ <svrl:message-code>BR-KSA-26</svrl:message-code>
994
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
995
+ </svrl:failed-assert>
996
+ </xsl:if>
997
+ </schxslt:rule>
998
+ <xsl:next-match>
999
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
1000
+ </xsl:next-match>
1001
+ </xsl:otherwise>
1002
+ </xsl:choose>
1003
+ </xsl:template>
1004
+ <xsl:template match="cac:AdditionalDocumentReference/cac:Attachment" priority="40" mode="d7e29">
1005
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1006
+ <xsl:choose>
1007
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
1008
+ <schxslt:rule pattern="d7e29">
1009
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:AdditionalDocumentReference/cac:Attachment" shadowed by preceding rule</xsl:comment>
1010
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1011
+ <xsl:attribute name="context">cac:AdditionalDocumentReference/cac:Attachment</xsl:attribute>
1012
+ </svrl:suppressed-rule>
1013
+ </schxslt:rule>
1014
+ <xsl:next-match>
1015
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1016
+ </xsl:next-match>
1017
+ </xsl:when>
1018
+ <xsl:otherwise>
1019
+ <schxslt:rule pattern="d7e29">
1020
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1021
+ <xsl:attribute name="context">cac:AdditionalDocumentReference/cac:Attachment</xsl:attribute>
1022
+ </svrl:fired-rule>
1023
+ <xsl:if test="boolean(//*[matches(@name, '02\d{5}')])">
1024
+ <xsl:if test="not(exists(cbc:EmbeddedDocumentBinaryObject) and (cbc:EmbeddedDocumentBinaryObject) != '' and (//ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sig:UBLDocumentSignatures/sac:SignatureInformation/cbc:ID) = 'urn:oasis:names:specification:ubl:signature:1')">
1025
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-28">
1026
+ <xsl:attribute name="test">exists(cbc:EmbeddedDocumentBinaryObject) and (cbc:EmbeddedDocumentBinaryObject) != '' and (//ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sig:UBLDocumentSignatures/sac:SignatureInformation/cbc:ID) = 'urn:oasis:names:specification:ubl:signature:1'</xsl:attribute>
1027
+ <svrl:text>[BR-KSA-28]-If the cryptographic stamp (KSA-15) exists in the invoice, this cryptographic stamp (KSA-15) must contain the exact "urn:oasis:names:specification:ubl:signature:1" value for signature information ID.</svrl:text>
1028
+ <svrl:message-code>BR-KSA-28</svrl:message-code>
1029
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1030
+ </svrl:failed-assert>
1031
+ </xsl:if>
1032
+ </xsl:if>
1033
+ <xsl:if test="boolean(//*[matches(@name, '02\d{5}')])">
1034
+ <xsl:if test="not(exists(cbc:EmbeddedDocumentBinaryObject) and (cbc:EmbeddedDocumentBinaryObject) != '' and (//cac:Signature/cbc:ID) = 'urn:oasis:names:specification:ubl:signature:Invoice')">
1035
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-29">
1036
+ <xsl:attribute name="test">exists(cbc:EmbeddedDocumentBinaryObject) and (cbc:EmbeddedDocumentBinaryObject) != '' and (//cac:Signature/cbc:ID) = 'urn:oasis:names:specification:ubl:signature:Invoice'</xsl:attribute>
1037
+ <svrl:text>[BR-KSA-29]-If the cryptographic stamp (KSA-15) exists in the invoice, this cryptographic stamp (KSA-15) must contain the exact "urn:oasis:names:specification:ubl:signature:Invoice" value for referenced signature ID and signature ID.</svrl:text>
1038
+ <svrl:message-code>BR-KSA-29</svrl:message-code>
1039
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1040
+ </svrl:failed-assert>
1041
+ </xsl:if>
1042
+ </xsl:if>
1043
+ <xsl:if test="boolean(//*[matches(@name, '02\d{5}')])">
1044
+ <xsl:if test="not(exists(cbc:EmbeddedDocumentBinaryObject) and (cbc:EmbeddedDocumentBinaryObject) != '' and (//cac:Signature/cbc:SignatureMethod) = 'urn:oasis:names:specification:ubl:dsig:enveloped:xades')">
1045
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-30">
1046
+ <xsl:attribute name="test">exists(cbc:EmbeddedDocumentBinaryObject) and (cbc:EmbeddedDocumentBinaryObject) != '' and (//cac:Signature/cbc:SignatureMethod) = 'urn:oasis:names:specification:ubl:dsig:enveloped:xades'</xsl:attribute>
1047
+ <svrl:text>[BR-KSA-30]-The document cryptographic stamp (KSA-15) must contain the exact "urn:oasis:names:specification:ubl:dsig:enveloped:xades" value for signature method.</svrl:text>
1048
+ <svrl:message-code>BR-KSA-30</svrl:message-code>
1049
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1050
+ </svrl:failed-assert>
1051
+ </xsl:if>
1052
+ </xsl:if>
1053
+ </schxslt:rule>
1054
+ <xsl:next-match>
1055
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
1056
+ </xsl:next-match>
1057
+ </xsl:otherwise>
1058
+ </xsl:choose>
1059
+ </xsl:template>
1060
+ <xsl:template match="cac:Delivery/cbc:LatestDeliveryDate" priority="39" mode="d7e29">
1061
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1062
+ <xsl:choose>
1063
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
1064
+ <schxslt:rule pattern="d7e29">
1065
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:Delivery/cbc:LatestDeliveryDate" shadowed by preceding rule</xsl:comment>
1066
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1067
+ <xsl:attribute name="context">cac:Delivery/cbc:LatestDeliveryDate</xsl:attribute>
1068
+ </svrl:suppressed-rule>
1069
+ </schxslt:rule>
1070
+ <xsl:next-match>
1071
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1072
+ </xsl:next-match>
1073
+ </xsl:when>
1074
+ <xsl:otherwise>
1075
+ <schxslt:rule pattern="d7e29">
1076
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1077
+ <xsl:attribute name="context">cac:Delivery/cbc:LatestDeliveryDate</xsl:attribute>
1078
+ </svrl:fired-rule>
1079
+ <xsl:if test="not(exists(../cbc:ActualDeliveryDate) and normalize-space(../cbc:ActualDeliveryDate) != '')">
1080
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
1081
+ location="{schxslt:location(.)}"
1082
+ flag="warning"
1083
+ id="BR-KSA-35">
1084
+ <xsl:attribute name="test">exists(../cbc:ActualDeliveryDate) and normalize-space(../cbc:ActualDeliveryDate) != ''</xsl:attribute>
1085
+ <svrl:text>[BR-KSA-35]-If the invoice contains a supply end date (KSA-24), then the invoice must contain a supply date (KSA-5).</svrl:text>
1086
+ </svrl:failed-assert>
1087
+ </xsl:if>
1088
+ <xsl:if test="(exists(../cbc:ActualDeliveryDate) and normalize-space(../cbc:ActualDeliveryDate) != '') and not(xs:date(.) &gt;= xs:date(../cbc:ActualDeliveryDate) )">
1089
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
1090
+ location="{schxslt:location(.)}"
1091
+ flag="warning"
1092
+ id="BR-KSA-36">
1093
+ <xsl:attribute name="test"> not(exists(../cbc:ActualDeliveryDate) and normalize-space(../cbc:ActualDeliveryDate) != '')and xs:date(.) &gt;= xs:date(../cbc:ActualDeliveryDate) </xsl:attribute>
1094
+ <svrl:text>[BR-KSA-36]-If the invoice contains a supply end date (KSA-24), then this date must be greater than or equal to the supply date (KSA-5).</svrl:text>
1095
+ </svrl:failed-assert>
1096
+ </xsl:if>
1097
+ </schxslt:rule>
1098
+ <xsl:next-match>
1099
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
1100
+ </xsl:next-match>
1101
+ </xsl:otherwise>
1102
+ </xsl:choose>
1103
+ </xsl:template>
1104
+ <xsl:template match="cac:AccountingSupplierParty/cac:Party" priority="38" mode="d7e29">
1105
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1106
+ <xsl:choose>
1107
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
1108
+ <schxslt:rule pattern="d7e29">
1109
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:AccountingSupplierParty/cac:Party" shadowed by preceding rule</xsl:comment>
1110
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1111
+ <xsl:attribute name="context">cac:AccountingSupplierParty/cac:Party</xsl:attribute>
1112
+ </svrl:suppressed-rule>
1113
+ </schxslt:rule>
1114
+ <xsl:next-match>
1115
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1116
+ </xsl:next-match>
1117
+ </xsl:when>
1118
+ <xsl:otherwise>
1119
+ <schxslt:rule pattern="d7e29">
1120
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1121
+ <xsl:attribute name="context">cac:AccountingSupplierParty/cac:Party</xsl:attribute>
1122
+ </svrl:fired-rule>
1123
+ <xsl:if test="not(matches(cac:PostalAddress/cbc:BuildingNumber, '^[0-9]{4}$'))">
1124
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-37">
1125
+ <xsl:attribute name="test">matches(cac:PostalAddress/cbc:BuildingNumber, '^[0-9]{4}$')</xsl:attribute>
1126
+ <svrl:text>[BR-KSA-37]-The seller address building number must contain 4 digits.</svrl:text>
1127
+ <svrl:message-code>BR-KSA-37</svrl:message-code>
1128
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1129
+ </svrl:failed-assert>
1130
+ </xsl:if>
1131
+ </schxslt:rule>
1132
+ <xsl:next-match>
1133
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
1134
+ </xsl:next-match>
1135
+ </xsl:otherwise>
1136
+ </xsl:choose>
1137
+ </xsl:template>
1138
+ <xsl:template match="//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme[cbc:ID = 'VAT'][//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID]" priority="37" mode="d7e29">
1139
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1140
+ <xsl:choose>
1141
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
1142
+ <schxslt:rule pattern="d7e29">
1143
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme[cbc:ID = 'VAT'][//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID]" shadowed by preceding rule</xsl:comment>
1144
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1145
+ <xsl:attribute name="context">//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme[cbc:ID = 'VAT'][//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID]</xsl:attribute>
1146
+ </svrl:suppressed-rule>
1147
+ </schxslt:rule>
1148
+ <xsl:next-match>
1149
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1150
+ </xsl:next-match>
1151
+ </xsl:when>
1152
+ <xsl:otherwise>
1153
+ <schxslt:rule pattern="d7e29">
1154
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1155
+ <xsl:attribute name="context">//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme[cbc:ID = 'VAT'][//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID]</xsl:attribute>
1156
+ </svrl:fired-rule>
1157
+ <xsl:if test="not(matches(//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID, '^[0-9]{15}$') and starts-with(//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID, '3') and ends-with(//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID, '3'))">
1158
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-40">
1159
+ <xsl:attribute name="test">matches(//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID, '^[0-9]{15}$') and starts-with(//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID, '3') and ends-with(//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID, '3')</xsl:attribute>
1160
+ <svrl:text>[BR-KSA-40]-If it exists in the invoice, the seller VAT registration number (BT-31) must contain 15 digits. The first and the last digits are "3"..</svrl:text>
1161
+ <svrl:message-code>BR-KSA-40</svrl:message-code>
1162
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1163
+ </svrl:failed-assert>
1164
+ </xsl:if>
1165
+ </schxslt:rule>
1166
+ <xsl:next-match>
1167
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
1168
+ </xsl:next-match>
1169
+ </xsl:otherwise>
1170
+ </xsl:choose>
1171
+ </xsl:template>
1172
+ <xsl:template match="cac:AccountingCustomerParty/cac:Party" priority="36" mode="d7e29">
1173
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1174
+ <xsl:choose>
1175
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
1176
+ <schxslt:rule pattern="d7e29">
1177
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:AccountingCustomerParty/cac:Party" shadowed by preceding rule</xsl:comment>
1178
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1179
+ <xsl:attribute name="context">cac:AccountingCustomerParty/cac:Party</xsl:attribute>
1180
+ </svrl:suppressed-rule>
1181
+ </schxslt:rule>
1182
+ <xsl:next-match>
1183
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1184
+ </xsl:next-match>
1185
+ </xsl:when>
1186
+ <xsl:otherwise>
1187
+ <schxslt:rule pattern="d7e29">
1188
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1189
+ <xsl:attribute name="context">cac:AccountingCustomerParty/cac:Party</xsl:attribute>
1190
+ </svrl:fired-rule>
1191
+ <xsl:if test="boolean(//*[matches(@name, '01\d{5}')])">
1192
+ <xsl:if test="not((cac:PartyLegalEntity/cbc:RegistrationName) != '')">
1193
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-42">
1194
+ <xsl:attribute name="test">(cac:PartyLegalEntity/cbc:RegistrationName) != ''</xsl:attribute>
1195
+ <svrl:text>The buyer name (BT-44) must be present in the tax invoice and associated credit notes and debit notes (KSA-2, position 1 and 2 = 01). </svrl:text>
1196
+ <svrl:message-code>BR-KSA-42</svrl:message-code>
1197
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1198
+ </svrl:failed-assert>
1199
+ </xsl:if>
1200
+ </xsl:if>
1201
+ </schxslt:rule>
1202
+ <xsl:next-match>
1203
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
1204
+ </xsl:next-match>
1205
+ </xsl:otherwise>
1206
+ </xsl:choose>
1207
+ </xsl:template>
1208
+ <xsl:template match="cac:InvoiceLine/cac:TaxTotal" priority="35" mode="d7e29">
1209
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1210
+ <xsl:choose>
1211
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
1212
+ <schxslt:rule pattern="d7e29">
1213
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:InvoiceLine/cac:TaxTotal" shadowed by preceding rule</xsl:comment>
1214
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1215
+ <xsl:attribute name="context">cac:InvoiceLine/cac:TaxTotal</xsl:attribute>
1216
+ </svrl:suppressed-rule>
1217
+ </schxslt:rule>
1218
+ <xsl:next-match>
1219
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1220
+ </xsl:next-match>
1221
+ </xsl:when>
1222
+ <xsl:otherwise>
1223
+ <schxslt:rule pattern="d7e29">
1224
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1225
+ <xsl:attribute name="context">cac:InvoiceLine/cac:TaxTotal</xsl:attribute>
1226
+ </svrl:fired-rule>
1227
+ <xsl:if test="not( format-number((cbc:RoundingAmount),'#.00') = format-number( (round(( (cbc:TaxAmount) + (../cbc:LineExtensionAmount) ) * 100 ) div 100), '#.00') )">
1228
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-51">
1229
+ <xsl:attribute name="test">(cbc:RoundingAmount) = (../cbc:LineExtensionAmount) + (cbc:TaxAmount)</xsl:attribute>
1230
+ <svrl:text>[BR-KSA-51]-The line amount with VAT (KSA-12) must be Invoice line net amount (BT-131) + Line VAT amount (KSA-11).</svrl:text>
1231
+ <svrl:message-code>BR-KSA-51</svrl:message-code>
1232
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1233
+ </svrl:failed-assert>
1234
+ </xsl:if>
1235
+ </schxslt:rule>
1236
+ <xsl:next-match>
1237
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
1238
+ </xsl:next-match>
1239
+ </xsl:otherwise>
1240
+ </xsl:choose>
1241
+ </xsl:template>
1242
+ <xsl:template match="/ubl:Invoice / cac:TaxTotal / cac:TaxSubtotal / cac:TaxCategory / cbc:ID | /ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:ID | /ubl:Invoice / cac:AllowanceCharge / cac:TaxCategory / cbc:ID | /ubl:Invoice / cac:InvoiceLine / cac:Item / cac:ClassifiedTaxCategory / cbc:ID" priority="35" mode="d7e29">
1243
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1244
+ <xsl:choose>
1245
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
1246
+ <schxslt:rule pattern="d7e29">
1247
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:InvoiceLine/cac:TaxTotal" shadowed by preceding rule</xsl:comment>
1248
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1249
+ <xsl:attribute name="context">cac:InvoiceLine/cac:TaxTotal</xsl:attribute>
1250
+ </svrl:suppressed-rule>
1251
+ </schxslt:rule>
1252
+ <xsl:next-match>
1253
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1254
+ </xsl:next-match>
1255
+ </xsl:when>
1256
+ <xsl:otherwise>
1257
+ <schxslt:rule pattern="d7e29">
1258
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1259
+ <xsl:attribute name="context">cac:InvoiceLine/cac:TaxTotal</xsl:attribute>
1260
+ </svrl:fired-rule>
1261
+ <!-- BR-KSA-18-->
1262
+ <xsl:if test="not( contains( ' S Z E O ',(.)) ) ">
1263
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-18">
1264
+ <xsl:attribute name="test">not( contains('S Z E O',/ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:ID) )</xsl:attribute>
1265
+ <svrl:text>[BR-KSA-18]-VAT category code must contain one of the values (S, Z, E, O).</svrl:text>
1266
+ <svrl:message-code>BR-KSA-18</svrl:message-code>
1267
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1268
+ </svrl:failed-assert>
1269
+ </xsl:if>
1270
+ <!-- END BR-KSA-18-->
1271
+ </schxslt:rule>
1272
+ <xsl:next-match>
1273
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
1274
+ </xsl:next-match>
1275
+ </xsl:otherwise>
1276
+ </xsl:choose>
1277
+ </xsl:template>
1278
+ <xsl:template match="/*/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'Z'] | /*/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'E'] | /*/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'O']" priority="33" mode="d7e29">
1279
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1280
+ <xsl:choose>
1281
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e29']">
1282
+ <schxslt:rule pattern="d7e29">
1283
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "/*/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'Z'][cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT']" shadowed by preceding rule</xsl:comment>
1284
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1285
+ <xsl:attribute name="context">/*/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'Z'][cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT']</xsl:attribute>
1286
+ </svrl:suppressed-rule>
1287
+ </schxslt:rule>
1288
+ <xsl:next-match>
1289
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1290
+ </xsl:next-match>
1291
+ </xsl:when>
1292
+ <xsl:otherwise>
1293
+ <schxslt:rule pattern="d7e29">
1294
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1295
+ <xsl:attribute name="context">/*/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'Z'][cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT']</xsl:attribute>
1296
+ </svrl:fired-rule>
1297
+ <xsl:if test="exists(cbc:TaxExemptionReason)">
1298
+ <xsl:if test="(string-length(cbc:TaxExemptionReason) &gt; 1000 or string-length(cbc:TaxExemptionReason) &lt; 1)">
1299
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C16">
1300
+ <xsl:attribute name="test">
1301
+ exists(cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount/cac:TaxCategory/cbc:TaxExemptionReason) and (string-length(cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount/cac:TaxCategory/cbc:TaxExemptionReason) &gt; 1000 or string-length(cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount/cac:TaxCategory/cbc:TaxExemptionReason) &lt; 1)
1302
+ </xsl:attribute>
1303
+ <svrl:text>[BR-KSA-F-06-C16]-Field character limits for VAT exemption reason text field (BT-120) have not been met. The minimum limit is 1 character and the maximum limit is 1000 characters.</svrl:text>
1304
+ <svrl:message-code>BR-KSA-F-06-C16</svrl:message-code>
1305
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1306
+ </svrl:failed-assert>
1307
+ </xsl:if>
1308
+ </xsl:if>
1309
+ </schxslt:rule>
1310
+ <xsl:next-match>
1311
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e29')"/>
1312
+ </xsl:next-match>
1313
+ </xsl:otherwise>
1314
+ </xsl:choose>
1315
+ </xsl:template>
1316
+ <xsl:template match="cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cac:Country[cbc:IdentificationCode = 'SA']" priority="29" mode="d7e29">
1317
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1318
+ <xsl:choose>
1319
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e212']">
1320
+ <schxslt:rule pattern="d7e212">
1321
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cac:Country[cbc:IdentificationCode = 'SA']" shadowed by preceding rule</xsl:comment>
1322
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1323
+ <xsl:attribute name="context">cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cac:Country[cbc:IdentificationCode = 'SA']</xsl:attribute>
1324
+ </svrl:suppressed-rule>
1325
+ </schxslt:rule>
1326
+ <xsl:next-match>
1327
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1328
+ </xsl:next-match>
1329
+ </xsl:when>
1330
+ <xsl:otherwise>
1331
+ <schxslt:rule pattern="d7e212">
1332
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1333
+ <xsl:attribute name="context">cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cac:Country[cbc:IdentificationCode = 'SA']</xsl:attribute>
1334
+ </svrl:fired-rule>
1335
+ <xsl:if test="boolean(//*[matches(@name, '01\d{5}')])">
1336
+ <xsl:if test="not((exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:BuildingNumber) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:PostalZone) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode)))">
1337
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-63">
1338
+ <xsl:attribute name="test">(exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:PlotIdentification) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:BuildingNumber) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:PostalZone) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode))</xsl:attribute>
1339
+ <svrl:text>[BR-KSA-63]-If the buyer country code (BT-55) is “SA”, then these fields are mandatory:street name (BT-50), building number (KSA-18), postal code (BT-53), city (BT-52), District (KSA-4), country code (BT-55).For more information please access this link:https://splonline.com.sa/en/national-address-1/</svrl:text>
1340
+ <svrl:message-code>BR-KSA-63</svrl:message-code>
1341
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1342
+ </svrl:failed-assert>
1343
+ </xsl:if>
1344
+ <xsl:if test="boolean(//*[matches(@name, '01\d{5}')]) and (not(exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName)) or (exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) &lt; 1))">
1345
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C28">
1346
+ <xsl:attribute name="test">
1347
+ exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) &lt; 1
1348
+ </xsl:attribute>
1349
+ <svrl:text>[BR-KSA-F-06-C28] - Field character limits for the Buyer Address - District field (KSA-4) have not been met. The minimum limit is 1 character and the maximum limit is 127 characters.
1350
+ </svrl:text>
1351
+ <svrl:message-code>BR-KSA-F-06-C28</svrl:message-code>
1352
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1353
+ </svrl:failed-assert>
1354
+ </xsl:if>
1355
+ <xsl:if test="exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) &gt; 127">
1356
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C29">
1357
+ <xsl:attribute name="test">
1358
+ exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) &gt; 127
1359
+ </xsl:attribute>
1360
+ <svrl:text>[BR-KSA-F-06-C29] - Field character limits for the Buyer Address - District field (KSA-4) have not been met. The maximum limit is 127 characters.
1361
+ </svrl:text>
1362
+ <svrl:message-code>BR-KSA-F-06-C29</svrl:message-code>
1363
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1364
+ </svrl:failed-assert>
1365
+ </xsl:if>
1366
+ </xsl:if>
1367
+ <xsl:if test="exists(//cac:AccountingSupplierParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) and (string-length(//cac:AccountingSupplierParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) &gt; 127 or string-length(//cac:AccountingSupplierParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) &lt; 1)">
1368
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C9">
1369
+ <xsl:attribute name="test">
1370
+ exists(//cac:AccountingSupplierParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) and (string-length(//cac:AccountingSupplierParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) &gt; 127 or string-length(//cac:AccountingSupplierParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) &lt; 1)
1371
+ </xsl:attribute>
1372
+ <svrl:text>[BR-KSA-F-06-C9] - Field character limits for the Seller Address - District field (KSA-3) have not been met. The minimum limit is 1 character and the maximum limit is 127 characters.
1373
+ </svrl:text>
1374
+ <svrl:message-code>BR-KSA-F-06-C9</svrl:message-code>
1375
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1376
+ </svrl:failed-assert>
1377
+ </xsl:if>
1378
+ <xsl:if test="boolean(//*[matches(@name, '01\d{5}')])">
1379
+ <xsl:if test="(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode) = 'SA' and not(matches(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:PostalZone, '^[0-9]{5}$'))">
1380
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-67">
1381
+ <xsl:attribute name="test">matches(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:PostalZone, '^[0-9]{5}$')</xsl:attribute>
1382
+ <svrl:text>[BR-KSA-67]-If the buyer country code (BT-55) is "SA", then the Buyer postal code(BT-53) must be 5 digits.</svrl:text>
1383
+ <svrl:message-code>BR-KSA-67</svrl:message-code>
1384
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1385
+ </svrl:failed-assert>
1386
+ </xsl:if>
1387
+ </xsl:if>
1388
+ <xsl:if test="boolean(//*[matches(@name, '02\d{3}1\d')])">
1389
+ <xsl:if test="not(exists(//cac:AccountingCustomerParty/cac:Party//cac:PartyLegalEntity/cbc:RegistrationName) and normalize-space(//cac:AccountingCustomerParty/cac:Party//cac:PartyLegalEntity/cbc:RegistrationName)!='')">
1390
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-71">
1391
+ <xsl:attribute name="test">not(exists(//cac:AccountingCustomerParty/cac:Party//cac:PartyLegalEntity/cbc:RegistrationName) and //cac:AccountingCustomerParty/cac:Party//cac:PartyLegalEntity/cbc:RegistrationName != '')</xsl:attribute>
1392
+ <svrl:text>If the Invoice is a simplified invoice type and is a summary invoice (KSA-2, position 1 and 2 = 02, position 6 = 1), then the buyer name must be present
1393
+ </svrl:text>
1394
+ <svrl:message-code>BR-KSA-71</svrl:message-code>
1395
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1396
+ </svrl:failed-assert>
1397
+ </xsl:if>
1398
+ <xsl:if test="not(//cbc:ActualDeliveryDate and //cbc:LatestDeliveryDate)">
1399
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-72">
1400
+ <xsl:attribute name="test">not(exists(/Invoice/cac:Delivery/cbc:ActualDeliveryDate)) or not(exists(/Invoice/cac:Delivery/cbc:LatestDeliveryDate))</xsl:attribute>
1401
+ <svrl:text>If the Invoice is a simplified invoice type and is a summary invoice (KSA-2, position 1 and 2 = 02, position 6 = 1), then a supply date (KSA-5) and supply end date (KSA-24) must be present
1402
+ </svrl:text>
1403
+ <svrl:message-code>BR-KSA-72</svrl:message-code>
1404
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1405
+ </svrl:failed-assert>
1406
+ </xsl:if>
1407
+ </xsl:if>
1408
+ </schxslt:rule>
1409
+ <xsl:next-match>
1410
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e212')"/>
1411
+ </xsl:next-match>
1412
+ </xsl:otherwise>
1413
+ </xsl:choose>
1414
+ </xsl:template>
1415
+ <xsl:template match="cbc:InvoiceTypeCode[substring(@name, 1, 2) = '01'] | cbc:InvoiceTypeCode[substring(@name, 1, 2) = '02']" priority="28" mode="d7e29">
1416
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1417
+ <xsl:choose>
1418
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e225']">
1419
+ <schxslt:rule pattern="d7e225">
1420
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cbc:InvoiceTypeCode[substring(@name, 1, 2) = '01']" shadowed by preceding rule</xsl:comment>
1421
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1422
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 1, 2) = '01']</xsl:attribute>
1423
+ </svrl:suppressed-rule>
1424
+ </schxslt:rule>
1425
+ <xsl:next-match>
1426
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1427
+ </xsl:next-match>
1428
+ </xsl:when>
1429
+ <xsl:otherwise>
1430
+ <schxslt:rule pattern="d7e225">
1431
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1432
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 1, 2) = '01']</xsl:attribute>
1433
+ </svrl:fired-rule>
1434
+ <xsl:if test="boolean(//*[matches(@name, '01\d{5}')])">
1435
+ <xsl:if test="not(every $line in //cac:InvoiceLine satisfies exists($line/cac:TaxTotal/cbc:TaxAmount) and ($line/cac:TaxTotal/cbc:TaxAmount) != '')">
1436
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-52">
1437
+ <xsl:attribute name="test">every $line in //cac:InvoiceLine satisfies exists($line/cac:TaxTotal/cbc:TaxAmount) and ($line/cac:TaxTotal/cbc:TaxAmount) != ''</xsl:attribute>
1438
+ <svrl:text>[BR-KSA-52]-The line VAT amount (KSA-11) is mandatory for tax invoice and associated credit notes and debit notes (KSA-2, position 1 and 2 = 01).</svrl:text>
1439
+ <svrl:message-code>BR-KSA-52</svrl:message-code>
1440
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1441
+ </svrl:failed-assert>
1442
+ </xsl:if>
1443
+ <xsl:if test="boolean(//*[matches(@name, '01\d{5}')]) and (not(exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName)) or (exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) and (string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) &gt; 1000 or string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) &lt; 1)))">
1444
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C23">
1445
+ <xsl:attribute name="test">
1446
+ boolean(//*[matches(@name, '01\d{5}')]) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) &lt; 1
1447
+ </xsl:attribute>
1448
+ <svrl:text>[BR-KSA-F-06-C23] - Field character limits for the Buyer Address - Street field (BT-50) have not been met. The minimum limit is 1 character and the maximum limit is 1000 characters.
1449
+ </svrl:text>
1450
+ <svrl:message-code>BR-KSA-F-06-C23</svrl:message-code>
1451
+ <svrl:message-category>Business rules - length constraints(BR)</svrl:message-category>
1452
+ </svrl:failed-assert>
1453
+ </xsl:if>
1454
+ <xsl:if test="boolean(//*[matches(@name, '01\d{5}')]) and (not(exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName)) or (exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) &lt; 1))">
1455
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C25">
1456
+ <xsl:attribute name="test">
1457
+ boolean(//*[matches(@name, '01\d{5}')]) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) &lt; 1
1458
+ </xsl:attribute>
1459
+ <svrl:text>[BR-KSA-F-06-C25] - Field character limits for the Buyer Address - City field (BT-52) have not been met. The minimum limit is 1 character and the maximum limit is 127 characters.
1460
+ </svrl:text>
1461
+ <svrl:message-code>BR-KSA-F-06-C25</svrl:message-code>
1462
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1463
+ </svrl:failed-assert>
1464
+ </xsl:if>
1465
+ </xsl:if>
1466
+ <xsl:if test="exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) and (string-length(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) &gt; 1000 or string-length(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) &lt; 1)">
1467
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C32">
1468
+ <xsl:attribute name="test">
1469
+ exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) &gt; 127
1470
+ </xsl:attribute>
1471
+ <svrl:text>[BR-KSA-F-06-C32] - Field character limits for Buyer name field (BT-44) have not been met. The maximum limit is 1000 characters.
1472
+ </svrl:text>
1473
+ <svrl:message-code>BR-KSA-F-06-C32</svrl:message-code>
1474
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1475
+ </svrl:failed-assert>
1476
+ </xsl:if>
1477
+ <xsl:if test="boolean(//*[matches(@name, '01\d{5}')]) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) and (string-length(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) &gt; 1000 or string-length(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) &lt; 1)">
1478
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C12">
1479
+ <xsl:attribute name="test">
1480
+ boolean(//*[matches(@name, '01\d{5}')]) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) &lt; 1
1481
+ </xsl:attribute>
1482
+ <svrl:text>[BR-KSA-F-06-C12] - Field character limits for Buyer name field (BT-44) have not been met. The minimum limit is 1 character and the maximum limit is 1000 characters.
1483
+ </svrl:text>
1484
+ <svrl:message-code>BR-KSA-F-06-C12</svrl:message-code>
1485
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1486
+ </svrl:failed-assert>
1487
+ </xsl:if>
1488
+ <xsl:if test="boolean(//*[matches(@name, '01\d{5}')])">
1489
+ <xsl:if test="not(every $line in //cac:InvoiceLine satisfies exists($line/cac:TaxTotal/cbc:RoundingAmount) and ($line/cac:TaxTotal/cbc:RoundingAmount) != '')">
1490
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-53">
1491
+ <xsl:attribute name="test">every $line in //cac:InvoiceLine satisfies exists($line/cac:TaxTotal/cbc:RoundingAmount) and ($line/cac:TaxTotal/cbc:RoundingAmount) != ''</xsl:attribute>
1492
+ <svrl:text>[BR-KSA-53]-The line amount with VAT (KSA-12) is mandatory for tax invoice and associated credit notes and debit notes (KSA-2, position 1 and 2 = 01).</svrl:text>
1493
+ <svrl:message-code>BR-KSA-53</svrl:message-code>
1494
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1495
+ </svrl:failed-assert>
1496
+ </xsl:if>
1497
+ </xsl:if>
1498
+ <xsl:if test="exists(//cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:PaymentNote) and (string-length(//cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:PaymentNote) &gt; 1000 or string-length(//cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:PaymentNote) &lt; 1)">
1499
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C14">
1500
+ <xsl:attribute name="test">
1501
+ exists(//cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:PaymentNote) and string-length(//cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:PaymentNote) &gt; 127
1502
+ </xsl:attribute>
1503
+ <svrl:text>[BR-KSA-F-06-C14]Field character limits for Payment terms field (KSA-22) have not been met. The maximum limit is 1000 characters.</svrl:text>
1504
+ <svrl:message-code>BR-KSA-F-06-C14</svrl:message-code>
1505
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1506
+ </svrl:failed-assert>
1507
+ </xsl:if>
1508
+ <xsl:if test="exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName)">
1509
+ <xsl:if test=" (string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) &gt; 1000 or string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) &lt; 1)">
1510
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C24">
1511
+ <xsl:attribute name="test">
1512
+ exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) &gt; 127
1513
+ </xsl:attribute>
1514
+ <svrl:text>[BR-KSA-F-06-C24] - Field character limits for the Buyer Address - Street field (BT-50) have not been met. The maximum limit is 1000 characters.
1515
+ </svrl:text>
1516
+ <svrl:message-code>BR-KSA-F-06-C24</svrl:message-code>
1517
+ <svrl:message-category>Business rules - length constraints(BR)</svrl:message-category>
1518
+ </svrl:failed-assert>
1519
+ </xsl:if>
1520
+ </xsl:if>
1521
+ <xsl:if test="exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) &gt; 127">
1522
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C26">
1523
+ <xsl:attribute name="test">
1524
+ exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) &gt; 127
1525
+ </xsl:attribute>
1526
+ <svrl:text>[BR-KSA-F-06-C26] - Field character limits for the Buyer Address - City field (BT-52) have not been met. The maximum limit is 127 characters.
1527
+ </svrl:text>
1528
+ <svrl:message-code>BR-KSA-F-06-C26</svrl:message-code>
1529
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1530
+ </svrl:failed-assert>
1531
+ </xsl:if>
1532
+ <xsl:for-each select="//cac:PaymentMeans/cbc:PaymentMeansCode">
1533
+ <xsl:if test="not(( ( not(contains(normalize-space(.),' ')) and contains( ' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 70 74 75 76 77 78 91 92 93 94 95 96 97 ZZZ ',concat(' ',normalize-space(.),' ') ) ) ))">
1534
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-16">
1535
+ <xsl:attribute name="test">exists(//cac:PaymentMeans) and exists(//cac:PaymentMeans/cbc:PaymentMeansCode) and contains(' 10 30 42 48 1 ', //cac:PaymentMeans/cbc:PaymentMeansCode)</xsl:attribute>
1536
+ <svrl:text>[BR-KSA-16]-Payment means code (BT-81) in an invoice exist, then it must contain one of the values from subset of UNTDID 4461 code list</svrl:text>
1537
+ <svrl:message-code>BR-KSA-16</svrl:message-code>
1538
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1539
+ </svrl:failed-assert>
1540
+ </xsl:if>
1541
+ </xsl:for-each>
1542
+ <xsl:if test="boolean(//*[matches(@name, '01\d{5}')])">
1543
+ <xsl:if test="not (string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode) &gt; 0 and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) &gt; 0 and string-length(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) &gt; 0 and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode))">
1544
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-10">
1545
+ <xsl:attribute name="test"> exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:PostalZone) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cbc:CitySubdivisionName) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode)</xsl:attribute>
1546
+ <svrl:text>[BR-KSA-10]-Buyer address must contain a street (BT-50), city (BT-52), country code (BT-55). This rule does not apply on the simplified tax invoices and associated credit notes and debit notes (KSA-2, position 1 and 2 = 02).</svrl:text>
1547
+ <svrl:message-code>BR-KSA-10</svrl:message-code>
1548
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1549
+ </svrl:failed-assert>
1550
+ </xsl:if>
1551
+ </xsl:if>
1552
+ <xsl:if test="boolean(//*[matches(@name, '01\d{5}')])">
1553
+ <xsl:if test="not(every $line in //cac:InvoiceLine satisfies exists($line/cac:TaxTotal/cbc:TaxAmount) and ($line/cac:TaxTotal/cbc:TaxAmount) != '')">
1554
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-54">
1555
+ <xsl:attribute name="test">every $line in //cac:InvoiceLine satisfies exists($line/cac:TaxTotal/cbc:TaxAmount) and ($line/cac:TaxTotal/cbc:TaxAmount) != ''</xsl:attribute>
1556
+ <svrl:text>[BR-KSA-54]-The line VAT amount (KSA-11) is mandatory for tax invoice and associated credit notes and debit notes (KSA-2, position 1 and 2 = 01).</svrl:text>
1557
+ <svrl:message-code>BR-KSA-54</svrl:message-code>
1558
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1559
+ </svrl:failed-assert>
1560
+ </xsl:if>
1561
+ </xsl:if>
1562
+ <xsl:if test="exists(//cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID) and string-length(//cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID) &gt; 127">
1563
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C15">
1564
+ <xsl:attribute name="test">
1565
+ exists(//cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID) and string-length(//cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID) &gt; 127
1566
+ </xsl:attribute>
1567
+ <svrl:text>[BR-KSA-F-06-C15] - Field character limits for Payment account identifier field (BT-84) have not been met. The maximum limit is 127 characters.
1568
+ </svrl:text>
1569
+ <svrl:message-code>BR-KSA-F-06-C15</svrl:message-code>
1570
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1571
+ </svrl:failed-assert>
1572
+ </xsl:if>
1573
+ </schxslt:rule>
1574
+ <xsl:next-match>
1575
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e225')"/>
1576
+ </xsl:next-match>
1577
+ </xsl:otherwise>
1578
+ </xsl:choose>
1579
+ </xsl:template>
1580
+ <xsl:template match="cbc:InvoiceTypeCode[substring(@name, 1, 2) = '01'][/ubl:Invoice[cbc:InvoiceTypeCode ='388']]" priority="27" mode="d7e29">
1581
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1582
+ <xsl:choose>
1583
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e246']">
1584
+ <schxslt:rule pattern="d7e246">
1585
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cbc:InvoiceTypeCode[substring(@name, 1, 2) = '01'][/ubl:Invoice[cbc:InvoiceTypeCode ='388']]" shadowed by preceding rule</xsl:comment>
1586
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1587
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 1, 2) = '01'][/ubl:Invoice[cbc:InvoiceTypeCode ='388']]</xsl:attribute>
1588
+ </svrl:suppressed-rule>
1589
+ </schxslt:rule>
1590
+ <xsl:next-match>
1591
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1592
+ </xsl:next-match>
1593
+ </xsl:when>
1594
+ <xsl:otherwise>
1595
+ <schxslt:rule pattern="d7e246">
1596
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1597
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 1, 2) = '01'][/ubl:Invoice[cbc:InvoiceTypeCode ='388']]</xsl:attribute>
1598
+ </svrl:fired-rule>
1599
+ <xsl:if test="not(exists(//cac:Delivery/cbc:ActualDeliveryDate) and normalize-space(//cac:Delivery/cbc:ActualDeliveryDate) != '')">
1600
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
1601
+ location="{schxslt:location(.)}"
1602
+ flag="warning"
1603
+ id="BR-KSA-15">
1604
+ <xsl:attribute name="test">exists(//cac:Delivery/cbc:ActualDeliveryDate) and normalize-space(//cac:Delivery/cbc:ActualDeliveryDate) != ''</xsl:attribute>
1605
+ <svrl:text>[BR-KSA-15]-The tax invoice ((invoice type code (BT-30) = 388) and (invoice transaction code (KSA-2) has "01" as first 2 digits)) must contain the supply date (KSA-5).</svrl:text>
1606
+ </svrl:failed-assert>
1607
+ </xsl:if>
1608
+ </schxslt:rule>
1609
+ <xsl:next-match>
1610
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e246')"/>
1611
+ </xsl:next-match>
1612
+ </xsl:otherwise>
1613
+ </xsl:choose>
1614
+ </xsl:template>
1615
+ <xsl:template match="cbc:InvoiceTypeCode[substring(@name, 1, 2) = '01'][/ubl:Invoice/cac:AccountingCustomerParty/cac:Party]" priority="26" mode="d7e29">
1616
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1617
+ <xsl:choose>
1618
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e255']">
1619
+ <schxslt:rule pattern="d7e255">
1620
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cbc:InvoiceTypeCode[substring(@name, 1, 2) = '01'][/ubl:Invoice/cac:AccountingCustomerParty/cac:Party]" shadowed by preceding rule</xsl:comment>
1621
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1622
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 1, 2) = '01'][/ubl:Invoice/cac:AccountingCustomerParty/cac:Party]</xsl:attribute>
1623
+ </svrl:suppressed-rule>
1624
+ </schxslt:rule>
1625
+ <xsl:next-match>
1626
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1627
+ </xsl:next-match>
1628
+ </xsl:when>
1629
+ <xsl:otherwise>
1630
+ <schxslt:rule pattern="d7e255">
1631
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1632
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 1, 2) = '01'][/ubl:Invoice/cac:AccountingCustomerParty/cac:Party]</xsl:attribute>
1633
+ </svrl:fired-rule>
1634
+ </schxslt:rule>
1635
+ <xsl:next-match>
1636
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e255')"/>
1637
+ </xsl:next-match>
1638
+ </xsl:otherwise>
1639
+ </xsl:choose>
1640
+ </xsl:template>
1641
+ <xsl:template match="/ubl:Invoice[cbc:InvoiceTypeCode = '381'] | /ubl:Invoice[cbc:InvoiceTypeCode = '383']" priority="25" mode="d7e29">
1642
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1643
+ <xsl:choose>
1644
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e264']">
1645
+ <schxslt:rule pattern="d7e264">
1646
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "/ubl:Invoice[cbc:InvoiceTypeCode = '381'] | /ubl:Invoice[cbc:InvoiceTypeCode = '383']" shadowed by preceding rule</xsl:comment>
1647
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1648
+ <xsl:attribute name="context">/ubl:Invoice[cbc:InvoiceTypeCode = '381'] | /ubl:Invoice[cbc:InvoiceTypeCode = '383']</xsl:attribute>
1649
+ </svrl:suppressed-rule>
1650
+ </schxslt:rule>
1651
+ <xsl:next-match>
1652
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1653
+ </xsl:next-match>
1654
+ </xsl:when>
1655
+ <xsl:otherwise>
1656
+ <schxslt:rule pattern="d7e264">
1657
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1658
+ <xsl:attribute name="context">/ubl:Invoice[cbc:InvoiceTypeCode = '381'] | /ubl:Invoice[cbc:InvoiceTypeCode = '383']</xsl:attribute>
1659
+ </svrl:fired-rule>
1660
+ <xsl:choose>
1661
+ <xsl:when test="count(//cac:PaymentMeans) &gt;0">
1662
+
1663
+
1664
+ <xsl:for-each select="//cac:PaymentMeans">
1665
+ <xsl:if test="not(exists(./cbc:InstructionNote))">
1666
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-17">
1667
+ <xsl:attribute name="test">exists(//cac:PaymentMeans/cbc:InstructionNote)</xsl:attribute>
1668
+ <svrl:text>[BR-KSA-17]-Debit and credit note (invoice type code (BT-3) is equal to 383 or 381) must contain the reason (KSA-10) for this invoice type issuing.</svrl:text>
1669
+ <svrl:message-code>BR-KSA-17</svrl:message-code>
1670
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1671
+ </svrl:failed-assert>
1672
+ </xsl:if>
1673
+ </xsl:for-each>
1674
+
1675
+
1676
+ </xsl:when>
1677
+ <xsl:otherwise>
1678
+
1679
+
1680
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-17">
1681
+ <xsl:attribute name="test">exists(//cac:PaymentMeans/cbc:InstructionNote)</xsl:attribute>
1682
+ <svrl:text>[BR-KSA-17]-Debit and credit note (invoice type code (BT-3) is equal to 383 or 381) must contain the reason (KSA-10) for this invoice type issuing.</svrl:text>
1683
+ <svrl:message-code>BR-KSA-17</svrl:message-code>
1684
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1685
+ </svrl:failed-assert>
1686
+
1687
+
1688
+ </xsl:otherwise>
1689
+ </xsl:choose>
1690
+ <xsl:for-each select="//cac:PaymentMeans/cbc:InstructionNote">
1691
+ <xsl:if test="exists(.) and (string-length(.) &gt; 1000 or string-length(.) &lt; 1)">
1692
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C13">
1693
+ <xsl:attribute name="test">
1694
+ exists(//cac:PaymentMeans/cbc:InstructionNote) and (string-length(//cac:PaymentMeans/cbc:InstructionNote) &gt; 1000 or string-length(//cac:PaymentMeans/cbc:InstructionNote) &lt; 1)
1695
+ </xsl:attribute>
1696
+ <svrl:text>[BR-KSA-F-06-C13] - Field character limits for Reasons for issuance of credit / debit note field (KSA-10) have not been met. The minimum limit is 1 character and the maximum limit is 1000 characters .
1697
+ </svrl:text>
1698
+ <svrl:message-code>BR-KSA-F-06-C13</svrl:message-code>
1699
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1700
+ </svrl:failed-assert>
1701
+ </xsl:if>
1702
+ </xsl:for-each>
1703
+ <xsl:choose>
1704
+ <xsl:when test="count(//cac:BillingReference) &gt; 0">
1705
+ <xsl:for-each select="//cac:BillingReference ">
1706
+ <xsl:if test="not(exists(./cac:InvoiceDocumentReference/cbc:ID) and (./cac:InvoiceDocumentReference/cbc:ID) != '')">
1707
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-56">
1708
+ <xsl:attribute name="test">exists(//cac:BillingReference/cac:InvoiceDocumentReference/cbc:ID) and (//cac:BillingReference/cac:InvoiceDocumentReference/cbc:ID) != ''</xsl:attribute>
1709
+ <svrl:text>[BR-KSA-56]-For credit notes ((BT-3) has the value of 381) and debit notes ((BT-3) has the value of 383), the billing reference ID (BT-25) is mandatory.</svrl:text>
1710
+ <svrl:message-code>BR-KSA-56</svrl:message-code>
1711
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1712
+ </svrl:failed-assert>
1713
+ </xsl:if>
1714
+ <xsl:if test="exists(./cac:InvoiceDocumentReference/cbc:ID) and (string-length(./cac:InvoiceDocumentReference/cbc:ID) &gt; 5000 or string-length(./cac:InvoiceDocumentReference/cbc:ID) &lt; 1)">
1715
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-F-06-C22">
1716
+ <xsl:attribute name="test">exists(//cac:BillingReference/cac:InvoiceDocumentReference/cbc:ID) and (string-length(//cac:BillingReference/cac:InvoiceDocumentReference/cbc:ID) &gt; 5000 or string-length(//cac:BillingReference/cac:InvoiceDocumentReference/cbc:ID) &lt; 1)</xsl:attribute>
1717
+ <svrl:text>[BR-KSA-F-06-C22]-Field character limits for Billing reference ID field (BT-25) have not been met. The minimum limit is 1 character and the maximum limit is 5000 characters.</svrl:text>
1718
+ <svrl:message-code>BR-KSA-F-06-C22</svrl:message-code>
1719
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1720
+ </svrl:failed-assert>
1721
+ </xsl:if>
1722
+ </xsl:for-each>
1723
+ </xsl:when>
1724
+ <xsl:otherwise>
1725
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-56">
1726
+ <xsl:attribute name="test">not(count(//cac:BillingReference) &gt; 0)</xsl:attribute>
1727
+ <svrl:text>[BR-KSA-56]-For credit notes ((BT-3) has the value of 381) and debit notes ((BT-3) has the value of 383), the billing reference ID (BT-25) is mandatory.</svrl:text>
1728
+ <svrl:message-code>BR-KSA-56</svrl:message-code>
1729
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1730
+ </svrl:failed-assert>
1731
+ </xsl:otherwise>
1732
+ </xsl:choose>
1733
+ </schxslt:rule>
1734
+ <xsl:next-match>
1735
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e264')"/>
1736
+ </xsl:next-match>
1737
+ </xsl:otherwise>
1738
+ </xsl:choose>
1739
+ </xsl:template>
1740
+ <xsl:template match="cbc:InvoiceTypeCode[substring(@name, 1, 2) = '02']" priority="24" mode="d7e29">
1741
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1742
+ <xsl:choose>
1743
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e276']">
1744
+ <schxslt:rule pattern="d7e276">
1745
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cbc:InvoiceTypeCode[substring(@name, 1, 2) = '02']" shadowed by preceding rule</xsl:comment>
1746
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1747
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 1, 2) = '02']</xsl:attribute>
1748
+ </svrl:suppressed-rule>
1749
+ </schxslt:rule>
1750
+ <xsl:next-match>
1751
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1752
+ </xsl:next-match>
1753
+ </xsl:when>
1754
+ <xsl:otherwise>
1755
+ <schxslt:rule pattern="d7e276">
1756
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1757
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 1, 2) = '02']</xsl:attribute>
1758
+ </svrl:fired-rule>
1759
+ <xsl:if test="not((every $taxreasoncode in //cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:TaxExemptionReasonCode satisfies contains(' VATEX-SA-HEA VATEX-SA-EDU ', $taxreasoncode) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) and (//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) != '') or not(every $taxreasoncode in //cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:TaxExemptionReasonCode satisfies contains(' VATEX-SA-HEA VATEX-SA-EDU ', $taxreasoncode)))">
1760
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-25">
1761
+ <xsl:attribute name="test">(every $taxreasoncode in //cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:TaxExemptionReasonCode satisfies contains(' VATEX-SA-HEA VATEX-SA-EDU ', $taxreasoncode) and exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) and (//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName) != '') or not(every $taxreasoncode in //cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:TaxExemptionReasonCode satisfies contains(' VATEX-SA-HEA VATEX-SA-EDU ', $taxreasoncode))</xsl:attribute>
1762
+ <svrl:text>[BR-KSA-25]-If it is a simplified tax invoice or an associated credit note or a debit note (KSA-2, position 1 and 2 = 02) and the tax exemption reason code (BT-121) is equal with VATEX-SA-EDU or VATEX-SA-HEA, then buyer name (BT-44) is mandatory.</svrl:text>
1763
+ <svrl:message-code>BR-KSA-25</svrl:message-code>
1764
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1765
+ </svrl:failed-assert>
1766
+ </xsl:if>
1767
+ <xsl:if test="not( (substring(./@name, 3,1) = '1' or substring(./@name, 3,1) = '0') and (substring(./@name, 4,1) = '1' or substring(./@name, 4,1) = '0') and (substring(./@name, 5,1) = '0') and (substring(./@name, 6,1) = '1' or substring(./@name, 6,1) = '0') and (substring(./@name, 7,1) = '0'))">
1768
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-31">
1769
+ <xsl:attribute name="test"> (substring(./@name, 3,1) = '1' or substring(./@name, 3,1) = '0') and (substring(./@name, 4,1) = '1' or substring(./@name, 4,1) = '0') and (substring(./@name, 5,1) = '0') and (substring(./@name, 6,1) = '1' or substring(./@name, 6,1) = '0') and (substring(./@name, 7,1) = '0')</xsl:attribute>
1770
+ <svrl:text>
1771
+ [BR-KSA-31]-For simplified tax invoices and associated credit notes and debit notes (KSA-2, position 1 and 2 = 02), only the following are accepted:
1772
+ third party (KSA-2, position 3 = 1),
1773
+ nominal supply (KSA-2, position 4 = 1) and
1774
+ summary transactions (KSA-2,, position 6 = 1).</svrl:text>
1775
+ <svrl:message-code>BR-KSA-31</svrl:message-code>
1776
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1777
+ </svrl:failed-assert>
1778
+ </xsl:if>
1779
+ <xsl:if test="not(exists(//cac:Signature) and (//cac:Signature) != '')">
1780
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-60">
1781
+ <xsl:attribute name="test">exists(//cac:Signature) and (//cac:Signature) != ''</xsl:attribute>
1782
+ <svrl:text>[BR-KSA-60]-Cryptographic stamp (KSA-15) must exist in simplified tax invoices and associated credit notes and debit notes (KSA-2, position 1 and 2 = 02).</svrl:text>
1783
+ <svrl:message-code>BR-KSA-60</svrl:message-code>
1784
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1785
+ </svrl:failed-assert>
1786
+ </xsl:if>
1787
+ </schxslt:rule>
1788
+ <xsl:next-match>
1789
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e276')"/>
1790
+ </xsl:next-match>
1791
+ </xsl:otherwise>
1792
+ </xsl:choose>
1793
+ </xsl:template>
1794
+ <xsl:template match="cbc:InvoiceTypeCode[substring(@name, 5, 1) = '1']" priority="23" mode="d7e29">
1795
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1796
+ <xsl:choose>
1797
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e291']">
1798
+ <schxslt:rule pattern="d7e291">
1799
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cbc:InvoiceTypeCode[substring(@name, 5, 1) = '1']" shadowed by preceding rule</xsl:comment>
1800
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1801
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 5, 1) = '1']</xsl:attribute>
1802
+ </svrl:suppressed-rule>
1803
+ </schxslt:rule>
1804
+ <xsl:next-match>
1805
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1806
+ </xsl:next-match>
1807
+ </xsl:when>
1808
+ <xsl:otherwise>
1809
+ <schxslt:rule pattern="d7e291">
1810
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1811
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 5, 1) = '1']</xsl:attribute>
1812
+ </svrl:fired-rule>
1813
+ <xsl:if test="not(substring(./@name,7,1) != '1')">
1814
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-07">
1815
+ <xsl:attribute name="test">substring(./@name,7,1) != '1'</xsl:attribute>
1816
+ <svrl:text>[BR-KSA-07]-Self billing is not allowed (KSA-2, position 7 cannot be "1") for export invoices (KSA-2, position 5 = 1).</svrl:text>
1817
+ <svrl:message-code>BR-KSA-07</svrl:message-code>
1818
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1819
+ </svrl:failed-assert>
1820
+ </xsl:if>
1821
+ </schxslt:rule>
1822
+ <xsl:next-match>
1823
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e291')"/>
1824
+ </xsl:next-match>
1825
+ </xsl:otherwise>
1826
+ </xsl:choose>
1827
+ </xsl:template>
1828
+ <xsl:template match="cbc:InvoiceTypeCode[substring(@name, 5, 1) = '0'][//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID]" priority="22" mode="d7e29">
1829
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1830
+ <xsl:choose>
1831
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e301']">
1832
+ <schxslt:rule pattern="d7e301">
1833
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cbc:InvoiceTypeCode[substring(@name, 5, 1) = '0'][//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID]" shadowed by preceding rule</xsl:comment>
1834
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1835
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 5, 1) = '0'][//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID]</xsl:attribute>
1836
+ </svrl:suppressed-rule>
1837
+ </schxslt:rule>
1838
+ <xsl:next-match>
1839
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1840
+ </xsl:next-match>
1841
+ </xsl:when>
1842
+ <xsl:otherwise>
1843
+ <schxslt:rule pattern="d7e301">
1844
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1845
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 5, 1) = '0'][//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID]</xsl:attribute>
1846
+ </svrl:fired-rule>
1847
+ <xsl:if test="string-length(//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID) &gt; 0 and not(exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID) and matches(//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID, '^[0-9]{15}$') and starts-with(//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID, '3') and ends-with(//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID, '3'))">
1848
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-44">
1849
+ <xsl:attribute name="test">matches(//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID, '^[0-9]{15}$') and starts-with(//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID, '3') and ends-with(//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID, '3')</xsl:attribute>
1850
+ <svrl:text>[BR-KSA-44]-If it exists in the invoice, and If it is not an export invoice (KSA-2, position 5 is false), the buyer VAT registration number (BT-48) must contain 15 digits. The first digit and the last digit is "3".</svrl:text>
1851
+ <svrl:message-code>BR-KSA-44</svrl:message-code>
1852
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1853
+ </svrl:failed-assert>
1854
+ </xsl:if>
1855
+ </schxslt:rule>
1856
+ <xsl:next-match>
1857
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e301')"/>
1858
+ </xsl:next-match>
1859
+ </xsl:otherwise>
1860
+ </xsl:choose>
1861
+ </xsl:template>
1862
+ <xsl:template match="cbc:InvoiceTypeCode[substring(@name, 5, 1) = '1'][//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID]" priority="21" mode="d7e29">
1863
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1864
+ <xsl:choose>
1865
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e310']">
1866
+ <schxslt:rule pattern="d7e310">
1867
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cbc:InvoiceTypeCode[substring(@name, 5, 1) = '1'][//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID]" shadowed by preceding rule</xsl:comment>
1868
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1869
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 5, 1) = '1'][//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID]</xsl:attribute>
1870
+ </svrl:suppressed-rule>
1871
+ </schxslt:rule>
1872
+ <xsl:next-match>
1873
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1874
+ </xsl:next-match>
1875
+ </xsl:when>
1876
+ <xsl:otherwise>
1877
+ <schxslt:rule pattern="d7e310">
1878
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1879
+ <xsl:attribute name="context">cbc:InvoiceTypeCode[substring(@name, 5, 1) = '1'][//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID]</xsl:attribute>
1880
+ </svrl:fired-rule>
1881
+ <xsl:if test="not(not(exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme)) and not(exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID)))">
1882
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-46">
1883
+ <xsl:attribute name="test">not(exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme)) and not(exists(//cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID))</xsl:attribute>
1884
+ <svrl:text>[BR-KSA-46]-If it is an export invoice (KSA-2, position 5 is true), the buyer VAT registration number or buyer group VAT registration number (BT-48) must not exist in the invoice.</svrl:text>
1885
+ <svrl:message-code>BR-KSA-46</svrl:message-code>
1886
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1887
+ </svrl:failed-assert>
1888
+ </xsl:if>
1889
+ </schxslt:rule>
1890
+ <xsl:next-match>
1891
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e310')"/>
1892
+ </xsl:next-match>
1893
+ </xsl:otherwise>
1894
+ </xsl:choose>
1895
+ </xsl:template>
1896
+ <xsl:template match="/ubl:Invoice" priority="19" mode="d7e29">
1897
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
1898
+ <xsl:choose>
1899
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e328']">
1900
+ <schxslt:rule pattern="d7e328">
1901
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:AllowanceCharge/cbc:MultiplierFactorNumeric | cac:InvoiceLine/cac:AllowanceCharge/cbc:MultiplierFactorNumeric" shadowed by preceding rule</xsl:comment>
1902
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1903
+ <xsl:attribute name="context">cac:AllowanceCharge/cbc:MultiplierFactorNumeric | cac:InvoiceLine/cac:AllowanceCharge/cbc:MultiplierFactorNumeric</xsl:attribute>
1904
+ </svrl:suppressed-rule>
1905
+ </schxslt:rule>
1906
+ <xsl:next-match>
1907
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
1908
+ </xsl:next-match>
1909
+ </xsl:when>
1910
+ <xsl:otherwise>
1911
+ <schxslt:rule pattern="d7e328">
1912
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
1913
+ <xsl:attribute name="context">cac:AllowanceCharge/cbc:MultiplierFactorNumeric | cac:InvoiceLine/cac:AllowanceCharge/cbc:MultiplierFactorNumeric</xsl:attribute>
1914
+ </svrl:fired-rule>
1915
+ <xsl:for-each select="//cac:AllowanceCharge[cbc:ChargeIndicator=false() and not(parent::cac:Price)]">
1916
+ <xsl:if test="string-length(cbc:MultiplierFactorNumeric) &gt; 0 and not(xs:decimal(cbc:MultiplierFactorNumeric) &gt;= 0 and xs:decimal(cbc:MultiplierFactorNumeric) &lt;= 100 and string-length(substring-after(cbc:MultiplierFactorNumeric,'.')) &lt;=2)">
1917
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-DEC-01">
1918
+ <xsl:attribute name="test">xs:decimal(.) &gt;= 0 and xs:decimal(.) &lt;= 100 and string-length(substring-after(.,'.')) &lt;=2</xsl:attribute>
1919
+ <svrl:text>[BR-KSA-DEC-01]-The allowance percentage values (BT-94, BT-138) must be from 0.00 to 100.00, with maximum two decimal places. Only numerals are accepted, the percentage symbol (%) is not allowed.</svrl:text>
1920
+ <svrl:message-code>BR-KSA-DEC-01</svrl:message-code>
1921
+ <svrl:message-category> KSA - decimals rules (BR-KSA-DEC)</svrl:message-category>
1922
+ </svrl:failed-assert>
1923
+ </xsl:if>
1924
+ </xsl:for-each>
1925
+ <xsl:for-each select="(./cac:AllowanceCharge[cbc:ChargeIndicator = true()])">
1926
+ <xsl:if test="not (exists(cbc:AllowanceChargeReasonCode) and normalize-space(cbc:AllowanceChargeReasonCode )!='' ) ">
1927
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-19">
1928
+ <xsl:attribute name="test">not((/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator = true()]/exists(cbc:AllowanceChargeReasonCode) ) or (/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator = true()]/exists(cbc:AllowanceChargeReason) ) )</xsl:attribute>
1929
+ <svrl:text>[BR-KSA-19]-Each Document level charge (BG-21) shall have a code for the reason for document level charge (BT-105).</svrl:text>
1930
+ <svrl:message-code>BR-KSA-19</svrl:message-code>
1931
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1932
+ </svrl:failed-assert>
1933
+ </xsl:if>
1934
+ <xsl:if test="not (exists(cbc:AllowanceChargeReason) and normalize-space(cbc:AllowanceChargeReason )!='' ) ">
1935
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-21">
1936
+ <xsl:attribute name="test">not((/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator = true()]/exists(cbc:AllowanceChargeReasonCode) ) or (/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator = true()]/exists(cbc:AllowanceChargeReason) ) )</xsl:attribute>
1937
+ <svrl:text>[BR-KSA-21]-Each Document level charge (BG-21) shall have a Reason for document level charge (BT-104).</svrl:text>
1938
+ <svrl:message-code>BR-KSA-21</svrl:message-code>
1939
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1940
+ </svrl:failed-assert>
1941
+ </xsl:if>
1942
+ <xsl:if test=" exists(cbc:AllowanceChargeReason)">
1943
+ <xsl:if test=" (string-length(cbc:AllowanceChargeReason) &gt; 1000 or string-length(cbc:AllowanceChargeReason) &lt; 1) ">
1944
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C33">
1945
+ <xsl:attribute name="test">string-length(cbc:AllowanceChargeReason) &gt; 1000 or string-length(cbc:AllowanceChargeReason) &lt; 1</xsl:attribute>
1946
+ <svrl:text>[BR-KSA-F-06-C33] -Field character limits for Reason for the document level charge (BT-104) have not been met. The maximum limit is 1,000 characters. </svrl:text>
1947
+ <svrl:message-code>BR-KSA-F-06-C33</svrl:message-code>
1948
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1949
+ </svrl:failed-assert>
1950
+ </xsl:if>
1951
+ </xsl:if>
1952
+ </xsl:for-each>
1953
+ <xsl:for-each select="(./cac:InvoiceLine/cac:AllowanceCharge[cbc:ChargeIndicator = true()])">
1954
+ <xsl:if test="not(exists(cbc:AllowanceChargeReasonCode) and normalize-space(cbc:AllowanceChargeReasonCode )!='' ) ">
1955
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-20">
1956
+ <xsl:attribute name="test">not( (/ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:ChargeIndicator=true()]/exists(cbc:AllowanceChargeReasonCode) ) or (/ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:ChargeIndicator=true()]/exists(cbc:AllowanceChargeReason) ) )</xsl:attribute>
1957
+ <svrl:text>[BR-KSA-20]-Each Invoice line charge (BG-28) shall have a code for the reason for invoice line charge (BT-145).</svrl:text>
1958
+ <svrl:message-code>BR-KSA-20</svrl:message-code>
1959
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1960
+ </svrl:failed-assert>
1961
+ </xsl:if>
1962
+ <xsl:if test="not( exists(cbc:AllowanceChargeReason)and normalize-space(cbc:AllowanceChargeReason )!='' )">
1963
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-22">
1964
+ <xsl:attribute name="test">not( (/ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:ChargeIndicator=true()]/exists(cbc:AllowanceChargeReasonCode) ) or (/ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:ChargeIndicator=true()]/exists(cbc:AllowanceChargeReason) ) )</xsl:attribute>
1965
+ <svrl:text>[BR-KSA-22]- Each Invoice line charge (BG-28) shall have a Reason for invoice line charge (BT-144).</svrl:text>
1966
+ <svrl:message-code>BR-KSA-22</svrl:message-code>
1967
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1968
+ </svrl:failed-assert>
1969
+ </xsl:if>
1970
+ <xsl:if test=" exists(cbc:AllowanceChargeReason)">
1971
+ <xsl:if test=" string-length(cbc:AllowanceChargeReason) &gt; 1000 or string-length(cbc:AllowanceChargeReason) &lt; 1">
1972
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C34">
1973
+ <xsl:attribute name="test">string-length(cbc:AllowanceChargeReason) &gt; 1000 or string-length(cbc:AllowanceChargeReason) &lt; 1</xsl:attribute>
1974
+ <svrl:text>[BR-KSA-F-06-C34] -Field character limits for Reason for invoice line charge (BT-144) have not been met. The maximum limit is 1,000 characters. </svrl:text>
1975
+ <svrl:message-code>BR-KSA-F-06-C34</svrl:message-code>
1976
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1977
+ </svrl:failed-assert>
1978
+ </xsl:if>
1979
+ </xsl:if>
1980
+ </xsl:for-each>
1981
+ <xsl:for-each select="(./cac:AllowanceCharge[cbc:ChargeIndicator = false()])">
1982
+ <xsl:if test=" exists(cbc:AllowanceChargeReason)">
1983
+ <xsl:if test=" string-length(cbc:AllowanceChargeReason) &gt; 1000 or string-length(cbc:AllowanceChargeReason) &lt; 1">
1984
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C35">
1985
+ <xsl:attribute name="test">string-length(cbc:AllowanceChargeReason) &gt; 1000 or string-length(cbc:AllowanceChargeReason) &lt; 1</xsl:attribute>
1986
+ <svrl:text>[BR-KSA-F-06-C35] -Field character limits for Reason for the document level allowance (BT-97) have not been met. The maximum limit is 1,000 characters. </svrl:text>
1987
+ <svrl:message-code>BR-KSA-F-06-C35</svrl:message-code>
1988
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
1989
+ </svrl:failed-assert>
1990
+ </xsl:if>
1991
+ </xsl:if>
1992
+ </xsl:for-each>
1993
+ <xsl:for-each select="(./cac:InvoiceLine/cac:Item/cac:ClassifiedTaxCategory[normalize-space(cbc:ID) = 'O'])">
1994
+ <xsl:if test="(cbc:Percent &gt;0 or cbc:Percent &lt;0 )">
1995
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-11">
1996
+ <xsl:attribute name="test">not(cbc:Percent)</xsl:attribute>
1997
+ <svrl:text>[BR-KSA-11]-An Invoice line (BG-25) where the VAT category code (BT-151) is "Not subject to VAT", an invoiced item VAT rate (BT-152) shall be 0 (zero), if exist.</svrl:text>
1998
+ <svrl:message-code>BR-KSA-11</svrl:message-code>
1999
+ <svrl:message-category>Business rules - Not subject to VAT (BR-OO)</svrl:message-category>
2000
+ </svrl:failed-assert>
2001
+ </xsl:if>
2002
+ </xsl:for-each>
2003
+
2004
+ <xsl:for-each select="(./cac:AllowanceCharge[cbc:ChargeIndicator=false()]/cac:TaxCategory[normalize-space(cbc:ID)='O'])">
2005
+ <xsl:if test="(cbc:Percent &gt;0 or cbc:Percent &lt;0 )">
2006
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-12">
2007
+ <xsl:attribute name="test">not(cbc:Percent)</xsl:attribute>
2008
+ <svrl:text>[BR-KSA-12]-A Document level allowance (BG-20) where VAT category code (BT-95) is "Not subject to VAT", a Document level allowance VAT rate (BT-96) shall be 0 (Zero), if exist.</svrl:text>
2009
+ <svrl:message-code>BR-KSA-12</svrl:message-code>
2010
+ <svrl:message-category>Business rules - Not subject to VAT (BR-OO)</svrl:message-category>
2011
+ </svrl:failed-assert>
2012
+ </xsl:if>
2013
+
2014
+ </xsl:for-each>
2015
+ <xsl:for-each select="(./cac:AllowanceCharge[cbc:ChargeIndicator=true()]/cac:TaxCategory[normalize-space(cbc:ID)='O'])">
2016
+
2017
+ <xsl:if test="(cbc:Percent &gt;0 or cbc:Percent &lt;0 )">
2018
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-13">
2019
+ <xsl:attribute name="test">not(cbc:Percent)</xsl:attribute>
2020
+ <svrl:text>[BR-KSA-13]-A Document level charge (BG-21) where the VAT category code (BT-102) is "Not subject to VAT", a Document level charge VAT rate (BT-103) shall be 0 (zero), if exist.</svrl:text>
2021
+ <svrl:message-code>BR-KSA-13</svrl:message-code>
2022
+ <svrl:message-category>Business rules - Not subject to VAT (BR-OO)</svrl:message-category>
2023
+ </svrl:failed-assert>
2024
+ </xsl:if>
2025
+ </xsl:for-each>
2026
+
2027
+ <xsl:for-each select="(./cac:InvoiceLine/cac:AllowanceCharge[cbc:ChargeIndicator = false()])">
2028
+ <xsl:if test=" exists(cbc:AllowanceChargeReason)">
2029
+ <xsl:if test=" string-length(cbc:AllowanceChargeReason) &gt; 1000 or string-length(cbc:AllowanceChargeReason) &lt; 1">
2030
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C36">
2031
+ <xsl:attribute name="test">string-length(cbc:AllowanceChargeReason) &gt; 1000 or string-length(cbc:AllowanceChargeReason) &lt; 1</xsl:attribute>
2032
+ <svrl:text>[BR-KSA-F-06-C36] -Field character limits for Reason for the invoice line allowance (BT-139) have not been met. The maximum limit is 1,000 characters. </svrl:text>
2033
+ <svrl:message-code>BR-KSA-F-06-C36</svrl:message-code>
2034
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
2035
+ </svrl:failed-assert>
2036
+ </xsl:if>
2037
+ </xsl:if>
2038
+ </xsl:for-each>
2039
+ </schxslt:rule>
2040
+ <xsl:next-match>
2041
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e328')"/>
2042
+ </xsl:next-match>
2043
+ </xsl:otherwise>
2044
+ </xsl:choose>
2045
+ </xsl:template>
2046
+ <xsl:template match="cac:AllowanceCharge/cac:TaxCategory/cbc:Percent | cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:Percent | cac:InvoiceLine/cac:Item/cac:ClassifiedTaxCategory/cbc:Percent | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:Percent" priority="18" mode="d7e29">
2047
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2048
+ <xsl:choose>
2049
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e328']">
2050
+ <schxslt:rule pattern="d7e328">
2051
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:AllowanceCharge/cac:TaxCategory/cbc:Percent | cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount/cac:TaxCategory/cbc:Percent | cac:InvoiceLine/cac:Item/cac:ClassifiedTaxCategory/cbc:Percent | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:Percent" shadowed by preceding rule</xsl:comment>
2052
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2053
+ <xsl:attribute name="context">cac:AllowanceCharge/cac:TaxCategory/cbc:Percent | cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount/cac:TaxCategory/cbc:Percent | cac:InvoiceLine/cac:Item/cac:ClassifiedTaxCategory/cbc:Percent | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:Percent</xsl:attribute>
2054
+ </svrl:suppressed-rule>
2055
+ </schxslt:rule>
2056
+ <xsl:next-match>
2057
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2058
+ </xsl:next-match>
2059
+ </xsl:when>
2060
+ <xsl:otherwise>
2061
+ <schxslt:rule pattern="d7e328">
2062
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2063
+ <xsl:attribute name="context">cac:AllowanceCharge/cac:TaxCategory/cbc:Percent | cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:Percent | cac:InvoiceLine/cac:Item/cac:ClassifiedTaxCategory/cbc:Percent | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:Percent</xsl:attribute>
2064
+ </svrl:fired-rule>
2065
+
2066
+ <xsl:if test="not(normalize-space(.)='')">
2067
+ <xsl:if test="not(xs:decimal(.) &gt;= 0 and xs:decimal(.) &lt;= 100 and string-length(substring-after(.,'.')) &lt;=2 and not (contains('%',(.))) )">
2068
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-DEC-02">
2069
+ <xsl:attribute name="test">xs:decimal(.) &gt;= 0 and xs:decimal(.) &lt;= 100 and string-length(substring-after(.,'.')) &lt;=2</xsl:attribute>
2070
+ <svrl:text>[BR-KSA-DEC-02]-The VAT rates (BT-96, BT-103, BT-119, BT-152, KSA-34) must be from 0.00 to 100.00, with maximum two decimals.Only numerals are accepted, the percentage symbol (%) is not allowed.</svrl:text>
2071
+ <svrl:message-code>BR-KSA-DEC-02</svrl:message-code>
2072
+ <svrl:message-category> KSA - decimals rules (BR-KSA-DEC)</svrl:message-category>
2073
+ </svrl:failed-assert>
2074
+ </xsl:if>
2075
+ </xsl:if>
2076
+ </schxslt:rule>
2077
+ <xsl:next-match>
2078
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e328')"/>
2079
+ </xsl:next-match>
2080
+ </xsl:otherwise>
2081
+ </xsl:choose>
2082
+ </xsl:template>
2083
+ <xsl:template match="cac:InvoiceLine" priority="17" mode="d7e29">
2084
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2085
+ <xsl:choose>
2086
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e328']">
2087
+ <schxslt:rule pattern="d7e328">
2088
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:InvoiceLine" shadowed by preceding rule</xsl:comment>
2089
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2090
+ <xsl:attribute name="context">cac:InvoiceLine</xsl:attribute>
2091
+ </svrl:suppressed-rule>
2092
+ </schxslt:rule>
2093
+ <xsl:next-match>
2094
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2095
+ </xsl:next-match>
2096
+ </xsl:when>
2097
+ <xsl:otherwise>
2098
+ <schxslt:rule pattern="d7e328">
2099
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2100
+ <xsl:attribute name="context">cac:InvoiceLine</xsl:attribute>
2101
+ </svrl:fired-rule>
2102
+ <xsl:if test="not(string-length(substring-after(cac:TaxTotal/cbc:TaxAmount,'.'))&lt;=2)">
2103
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-DEC-03">
2104
+ <xsl:attribute name="test">string-length(substring-after(cac:TaxTotal/cbc:TaxAmount,'.'))&lt;=2</xsl:attribute>
2105
+ <svrl:text>[BR-KSA-DEC-03]-VAT amount at line level (KSA-11) must have a maximum two decimals.</svrl:text>
2106
+ <svrl:message-code>BR-KSA-DEC-03</svrl:message-code>
2107
+ <svrl:message-category> KSA - decimals rules (BR-KSA-DEC)</svrl:message-category>
2108
+ </svrl:failed-assert>
2109
+ </xsl:if>
2110
+ <xsl:if test="not(string-length(substring-after(cac:TaxTotal/cbc:RoundingAmount,'.'))&lt;=2)">
2111
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-DEC-04">
2112
+ <xsl:attribute name="test">string-length(substring-after(cac:TaxTotal/cbc:RoundingAmount,'.'))&lt;=2</xsl:attribute>
2113
+ <svrl:text>[BR-KSA-DEC-04]-Amount with VAT at line level (KSA-12) must have a maximum two decimals.</svrl:text>
2114
+ <svrl:message-code>BR-KSA-DEC-04</svrl:message-code>
2115
+ <svrl:message-category> KSA - decimals rules (BR-KSA-DEC)</svrl:message-category>
2116
+ </svrl:failed-assert>
2117
+ </xsl:if>
2118
+ </schxslt:rule>
2119
+ <xsl:next-match>
2120
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e328')"/>
2121
+ </xsl:next-match>
2122
+ </xsl:otherwise>
2123
+ </xsl:choose>
2124
+ </xsl:template>
2125
+ <xsl:template match="cbc:DocumentCurrencyCode | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount/@currencyID | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount/@currencyID | cac:LegalMonetaryTotal / cbc:PayableRoundingAmount / @currencyID" priority="16" mode="d7e29">
2126
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2127
+ <xsl:choose>
2128
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e355']">
2129
+ <schxslt:rule pattern="d7e355">
2130
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cbc:DocumentCurrencyCode" shadowed by preceding rule</xsl:comment>
2131
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl" flag="error">
2132
+ <xsl:attribute name="context">cbc:DocumentCurrencyCode | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount/@currencyID | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount/@currencyID</xsl:attribute>
2133
+ </svrl:suppressed-rule>
2134
+ </schxslt:rule>
2135
+ <xsl:next-match>
2136
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2137
+ </xsl:next-match>
2138
+ </xsl:when>
2139
+ <xsl:otherwise>
2140
+ <schxslt:rule pattern="d7e355">
2141
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl" flag="error">
2142
+ <xsl:attribute name="context">cbc:DocumentCurrencyCode | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount/@currencyID | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount/@currencyID</xsl:attribute>
2143
+ </svrl:fired-rule>
2144
+ <xsl:if test="not(((not(contains(normalize-space(.), ' ')) and contains(' AED AFN ALL AMD ANG AOA ARS AUD AWG AZN BAM BBD BDT BGN BHD BIF BMD BND BOB BOV BRL BSD BTN BWP BYN BZD CAD CDF CHE CHF CHW CLF CLP CNY COP COU CRC CUC CUP CVE CZK DJF DKK DOP DZD EGP ERN ETB EUR FJD FKP GBP GEL GHS GIP GMD GNF GTQ 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 LYD 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 SSP STD SVC SYP SZL THB TJS TMT TND TOP TRY TTD TWD TZS UAH UGX USD USN UYI UYU UZS VEF VND VUV WST XAF XAG XAU XBA XBB XBC XBD XCD XDR XOF XPD XPF XPT XSU XTS XUA XXX YER ZAR ZMW ZWL ', concat(' ', normalize-space(.), ' ')))))">
2145
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-CL-01">
2146
+ <xsl:attribute name="test">((not(contains(normalize-space(.), ' ')) and contains(' AED AFN ALL AMD ANG AOA ARS AUD AWG AZN BAM BBD BDT BGN BHD BIF BMD BND BOB BOV BRL BSD BTN BWP BYN BZD CAD CDF CHE CHF CHW CLF CLP CNY COP COU CRC CUC CUP CVE CZK DJF DKK DOP DZD EGP ERN ETB EUR FJD FKP GBP GEL GHS GIP GMD GNF GTQ 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 LYD 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 SSP STD SVC SYP SZL THB TJS TMT TND TOP TRY TTD TWD TZS UAH UGX USD USN UYI UYU UZS VEF VND VUV WST XAF XAG XAU XBA XBB XBC XBD XCD XDR XOF XPD XPF XPT XSU XTS XUA XXX YER ZAR ZMW ZWL ', concat(' ', normalize-space(.), ' '))))</xsl:attribute>
2147
+ <svrl:text>[BR-KSA-CL-01]-Currency code (BT-5) must be according to ISO 4217:2005</svrl:text>
2148
+ <svrl:message-code>BR-KSA-CL-01</svrl:message-code>
2149
+ <svrl:message-category>KSA - code list (BR-KSA-CL)</svrl:message-category>
2150
+ </svrl:failed-assert>
2151
+ </xsl:if>
2152
+ </schxslt:rule>
2153
+ <xsl:next-match>
2154
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e355')"/>
2155
+ </xsl:next-match>
2156
+ </xsl:otherwise>
2157
+ </xsl:choose>
2158
+ </xsl:template>
2159
+ <xsl:template match="cbc:Amount | cbc:BaseAmount | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount | cbc:LineExtensionAmount |cbc:PriceAmount | cbc:TaxExclusiveAmount | cbc:TaxInclusiveAmount | cbc:AllowanceTotalAmount | cbc:ChargeTotalAmount | cbc:PrepaidAmount | cbc:PayableRoundingAmount | cbc:PayableAmount | cac:InvoiceLine/cac:TaxTotal/cbc:TaxAmount | cac:InvoiceLine/cac:TaxTotal/cbc:RoundingAmount |cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount | cac:LegalMonetaryTotal / cbc:PayableRoundingAmount " priority="15" mode="d7e29">
2160
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2161
+ <xsl:choose>
2162
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e355']">
2163
+ <schxslt:rule pattern="d7e355">
2164
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cbc:Amount | cbc:BaseAmount | cbc:PriceAmount | cbc:LineExtensionAmount | cbc:TaxExclusiveAmount | cbc:TaxInclusiveAmount | cbc:AllowanceTotalAmount | cbc:ChargeTotalAmount | cbc:PrepaidAmount | cbc:PayableRoundingAmount | cbc:PayableAmount | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount " shadowed by preceding rule</xsl:comment>
2165
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl" flag="error">
2166
+ <xsl:attribute name="context">cbc:Amount | cbc:BaseAmount | cbc:PriceAmount | cbc:LineExtensionAmount | cbc:TaxExclusiveAmount | cbc:TaxInclusiveAmount | cbc:AllowanceTotalAmount | cbc:ChargeTotalAmount | cbc:PrepaidAmount | cbc:PayableRoundingAmount | cbc:PayableAmount | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount </xsl:attribute>
2167
+ </svrl:suppressed-rule>
2168
+ </schxslt:rule>
2169
+ <xsl:next-match>
2170
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2171
+ </xsl:next-match>
2172
+ </xsl:when>
2173
+ <xsl:otherwise>
2174
+ <schxslt:rule pattern="d7e355">
2175
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl" flag="error">
2176
+ <xsl:attribute name="context">cbc:Amount | cbc:BaseAmount | cbc:PriceAmount | cbc:LineExtensionAmount | cbc:TaxExclusiveAmount | cbc:TaxInclusiveAmount | cbc:AllowanceTotalAmount | cbc:ChargeTotalAmount | cbc:PrepaidAmount | cbc:PayableRoundingAmount | cbc:PayableAmount | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount | cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount </xsl:attribute>
2177
+ </svrl:fired-rule>
2178
+ <xsl:if test="exists(.) ">
2179
+ <xsl:if test="not(exists(@currencyID) and matches(normalize-space(//cbc:DocumentCurrencyCode), @currencyID) and (@currencyID !='') )">
2180
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-CL-02">
2181
+ <xsl:attribute name="test">matches(normalize-space(//cbc:DocumentCurrencyCode), @currencyID)</xsl:attribute>
2182
+ <svrl:text>[BR-KSA-CL-02]-All currencyID attributes (BT-5) must have the same value as the invoice currency code (BT-5), except for the invoice total VAT amount in accounting currency (BT-111).</svrl:text>
2183
+ <svrl:message-code>BR-KSA-CL-02</svrl:message-code>
2184
+ <svrl:message-category>KSA - code list (BR-KSA-CL)</svrl:message-category>
2185
+ </svrl:failed-assert>
2186
+ </xsl:if>
2187
+ </xsl:if>
2188
+ </schxslt:rule>
2189
+ <xsl:next-match>
2190
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e355')"/>
2191
+ </xsl:next-match>
2192
+ </xsl:otherwise>
2193
+ </xsl:choose>
2194
+ </xsl:template>
2195
+ <xsl:template match="cac:AdditionalDocumentReference/cac:Attachment/cbc:EmbeddedDocumentBinaryObject" priority="14" mode="d7e29">
2196
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2197
+ <xsl:choose>
2198
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e355']">
2199
+ <schxslt:rule pattern="d7e355">
2200
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:AdditionalDocumentReference/cac:Attachment/cbc:EmbeddedDocumentBinaryObject" shadowed by preceding rule</xsl:comment>
2201
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl" flag="error">
2202
+ <xsl:attribute name="context">cac:AdditionalDocumentReference/cac:Attachment/cbc:EmbeddedDocumentBinaryObject</xsl:attribute>
2203
+ </svrl:suppressed-rule>
2204
+ </schxslt:rule>
2205
+ <xsl:next-match>
2206
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2207
+ </xsl:next-match>
2208
+ </xsl:when>
2209
+ <xsl:otherwise>
2210
+ <schxslt:rule pattern="d7e355">
2211
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl" flag="error">
2212
+ <xsl:attribute name="context">cac:AdditionalDocumentReference/cac:Attachment/cbc:EmbeddedDocumentBinaryObject</xsl:attribute>
2213
+ </svrl:fired-rule>
2214
+ <xsl:if test="not(((not(contains(normalize-space(@mimeCode), ' ')) and contains(' text/csv text/plain application/pdf image/png image/jpeg image/tiff application/acad application/dwg drawing/dwg application/vnd.openxmlformats-officedocument.spreadsheetml.sheet application/vnd.oasis.opendocument.spreadsheet ', concat(' ', normalize-space(@mimeCode), ' ')))))">
2215
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-CL-03">
2216
+ <xsl:attribute name="test">((not(contains(normalize-space(@mimeCode), ' ')) and contains(' text/csv text/plain application/pdf image/png image/jpeg image/tiff application/acad application/dwg drawing/dwg application/vnd.openxmlformats-officedocument.spreadsheetml.sheet application/vnd.oasis.opendocument.spreadsheet ', concat(' ', normalize-space(@mimeCode), ' '))))</xsl:attribute>
2217
+ <svrl:text>[BR-KSA-CL-03]-Mime code must be according to subset of IANA code list.</svrl:text>
2218
+ <svrl:message-code>BR-KSA-CL-03</svrl:message-code>
2219
+ <svrl:message-category>KSA - code list (BR-KSA-CL)</svrl:message-category>
2220
+ </svrl:failed-assert>
2221
+ </xsl:if>
2222
+ </schxslt:rule>
2223
+ <xsl:next-match>
2224
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e355')"/>
2225
+ </xsl:next-match>
2226
+ </xsl:otherwise>
2227
+ </xsl:choose>
2228
+ </xsl:template>
2229
+ <xsl:template match="ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'Z'] |ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'E'] | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'O'] " priority="13" mode="d7e29">
2230
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2231
+ <xsl:choose>
2232
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e355']">
2233
+ <schxslt:rule pattern="d7e355">
2234
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'Z'] | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'E'] | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'O'] " shadowed by preceding rule</xsl:comment>
2235
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl" flag="error">
2236
+ <xsl:attribute name="context">ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'Z'] | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'E'] | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'O'] </xsl:attribute>
2237
+ </svrl:suppressed-rule>
2238
+ </schxslt:rule>
2239
+ <xsl:next-match>
2240
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2241
+ </xsl:next-match>
2242
+ </xsl:when>
2243
+ <xsl:otherwise>
2244
+ <schxslt:rule pattern="d7e355">
2245
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl" flag="error">
2246
+ <xsl:attribute name="context">ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'Z'] | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'E'] | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[normalize-space(cbc:ID) = 'O'] </xsl:attribute>
2247
+ </svrl:fired-rule>
2248
+ <!--xsl:variable name="taxExemptionReason" select="concat(cbc:TaxExemptionReasonCode, replace(cbc:TaxExemptionReason,' ',''))"/>
2249
+ <xsl:if test="(exists(cbc:TaxExemptionReasonCode) and ((not(contains(normalize-space(cbc:TaxExemptionReasonCode), ' ')) and normalize-space(cbc:ID) ='Z' and contains(' VATEX-SA-32 VATEX-SA-33 VATEX-SA-34-1 VATEX-SA-34-2 VATEX-SA-34-3 VATEX-SA-34-4 VATEX-SA-34-5 VATEX-SA-35 VATEX-SA-36 VATEX-SA-EDU VATEX-SA-HEA VATEX-SA-MLTRY ', concat(' ', normalize-space(cbc:TaxExemptionReasonCode), ' ')))) or ((not(contains(normalize-space(cbc:TaxExemptionReasonCode), ' ')) and normalize-space(cbc:ID) ='E' and contains(' VATEX-SA-29 VATEX-SA-29-7 VATEX-SA-30 ', concat(' ', normalize-space(cbc:TaxExemptionReasonCode), ' ')))) or ((not(contains(normalize-space(cbc:TaxExemptionReasonCode), ' ')) and normalize-space(cbc:ID) ='O' and contains(' VATEX-SA-OOS ', concat(' ', normalize-space(cbc:TaxExemptionReasonCode), ' ')))) or normalize-space(cbc:TaxExemptionReasonCode)='' )">
2250
+ <xsl:if test="not((contains($taxExemptionReason, 'VATEX-SA-29FinancialservicesmentionedinArticle29oftheVATRegulations') and string-length($taxExemptionReason) &lt;68) or (contains($taxExemptionReason, 'VATEX-SA-29-7LifeinsuranceservicesmentionedinArticle29oftheVATRegulations')and string-length($taxExemptionReason) &lt;74) or (contains($taxExemptionReason, 'VATEX-SA-30RealestatetransactionsmentionedinArticle30oftheVATRegulations') and string-length($taxExemptionReason) &lt;73) or( contains($taxExemptionReason, 'VATEX-SA-32Exportofgoods') and string-length($taxExemptionReason) &lt;25 )or (contains($taxExemptionReason, 'VATEX-SA-33Exportofservices') and string-length($taxExemptionReason) &lt;28 ) or (contains($taxExemptionReason, 'VATEX-SA-34-1TheinternationaltransportofGoods') and string-length($taxExemptionReason) &lt;46 ) or (contains($taxExemptionReason, 'VATEX-SA-34-2internationaltransportofpassengers') and string-length($taxExemptionReason) &lt;48 ) or (contains($taxExemptionReason, 'VATEX-SA-34-3servicesdirectlyconnectedandincidentaltoaSupplyofinternationalpassengertransport') and string-length($taxExemptionReason) &lt;94 ) or (contains($taxExemptionReason, 'VATEX-SA-34-4Supplyofaqualifyingmeansoftransport') and string-length($taxExemptionReason) &lt;49 ) or (contains($taxExemptionReason, 'VATEX-SA-34-5AnyservicesrelatingtoGoodsorpassengertransportation,asdefinedinarticletwentyfiveoftheseRegulations') and string-length($taxExemptionReason) &lt;112 )or (contains($taxExemptionReason, 'VATEX-SA-35Medicinesandmedicalequipment') and string-length($taxExemptionReason) &lt;40 ) or (contains($taxExemptionReason, 'VATEX-SA-36Qualifyingmetals') and string-length($taxExemptionReason) &lt;28 ) or (contains($taxExemptionReason, 'VATEX-SA-EDUPrivateeducationtocitizen') and string-length($taxExemptionReason) &lt;38 ) or (contains($taxExemptionReason, 'VATEX-SA-HEAPrivatehealthcaretocitizen') and string-length($taxExemptionReason) &lt;39 ) or (matches(normalize-space(cbc:TaxExemptionReasonCode),'VATEX-SA-OOS') )or (contains($taxExemptionReason, 'VATEX-SA-MLTRYsupplyofqualifiedmilitarygoods') and string-length($taxExemptionReason) &lt;45 ) or (normalize-space(cbc:TaxExemptionReasonCode)=''))">
2251
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-83">
2252
+ <xsl:attribute name="test">exists(cbc:TaxExemptionReason) </xsl:attribute>
2253
+ <svrl:text>[BR-KSA-83]-A VAT breakdown (BG-23) with VAT Category code (BT-118) 'Exempt from VAT' or 'Zero rated' or 'Not subject to VAT' shall have a VAT exemption (or exception) reason text (BT-120) with one of the values from paragraph 11.2.4 of XML implementation standards on Tax exemption (or exception) reason text - specific to Saudi Arabia. </svrl:text>
2254
+ <svrl:message-code>BR-KSA-83</svrl:message-code>
2255
+ <svrl:message-category>KSA - code list (BR-KSA)</svrl:message-category>
2256
+ </svrl:failed-assert>
2257
+ </xsl:if>
2258
+ </xsl:if
2259
+ (done by abdulkareem)
2260
+ -->
2261
+ <xsl:if test="exists(cbc:TaxExemptionReasonCode)">
2262
+ <xsl:if test="not(exists(cbc:TaxExemptionReason) and normalize-space(cbc:TaxExemptionReason))">
2263
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-83">
2264
+ <xsl:attribute name="test">exists(cbc:TaxExemptionReason) </xsl:attribute>
2265
+ <svrl:text>[BR-KSA-83]-A VAT breakdown (BG-23) with VAT Category code (BT-118) 'Exempt from VAT' or 'Zero rated' or 'Not subject to VAT' shall have a VAT exemption (or exception) reason text (BT-120) with one of the values from paragraph 11.2.4 of XML implementation standards on Tax exemption (or exception) reason text - specific to Saudi Arabia. </svrl:text>
2266
+ <svrl:message-code>BR-KSA-83</svrl:message-code>
2267
+ <svrl:message-category>KSA - code list (BR-KSA-CL)</svrl:message-category>
2268
+ </svrl:failed-assert>
2269
+ </xsl:if>
2270
+ </xsl:if>
2271
+
2272
+ <xsl:if test="not(exists(cbc:TaxExemptionReasonCode) and ((not(contains(normalize-space(cbc:TaxExemptionReasonCode), ' ')) and normalize-space(cbc:ID) ='Z' and contains(' VATEX-SA-32 VATEX-SA-33 VATEX-SA-34-1 VATEX-SA-34-2 VATEX-SA-34-3 VATEX-SA-34-4 VATEX-SA-34-5 VATEX-SA-35 VATEX-SA-36 VATEX-SA-EDU VATEX-SA-HEA VATEX-SA-MLTRY VATEX-SA-DIPLOMAT ', concat(' ', normalize-space(cbc:TaxExemptionReasonCode), ' ')))) or ((not(contains(normalize-space(cbc:TaxExemptionReasonCode), ' ')) and normalize-space(cbc:ID) ='E' and contains(' VATEX-SA-29 VATEX-SA-29-7 VATEX-SA-30 ', concat(' ', normalize-space(cbc:TaxExemptionReasonCode), ' ')))) or ((not(contains(normalize-space(cbc:TaxExemptionReasonCode), ' ')) and normalize-space(cbc:ID) ='O' and contains(' VATEX-SA-OOS ', concat(' ', normalize-space(cbc:TaxExemptionReasonCode), ' ')))) or normalize-space(cbc:TaxExemptionReasonCode)='' )">
2273
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-CL-04">
2274
+ <xsl:attribute name="test">exists(cbc:TaxExemptionReasonCode) and ((not(contains(normalize-space(cbc:TaxExemptionReasonCode), ' ')) and contains(' VATEX-SA-32 VATEX-SA-33 VATEX-SA-34-1 VATEX-SA-34-2 VATEX-SA-34-3 VATEX-SA-34-4 VATEX-SA-34-5 VATEX-SA-35 VATEX-SA-36 VATEX-SA-EDU VATEX-SA-HEA VATEX-SA-MLTRY VATEX-SA-DIPLOMAT ', concat(' ', normalize-space(cbc:TaxExemptionReasonCode), ' '))))</xsl:attribute>
2275
+ <svrl:text>[BR-KSA-CL-04]-If VAT category Code (BT-118) is 'Z', or 'E' or 'O', VAT exemption (or exception) reason code (BT-121) must exist with one of the values from paragraph 11.2.4 of XML implementation standards on Tax exemption (or exception) reason code - specific to Saudi Arabia. </svrl:text>
2276
+ <svrl:message-code>BR-KSA-CL-04</svrl:message-code>
2277
+ <svrl:message-category>KSA - code list (BR-KSA-CL)</svrl:message-category>
2278
+ </svrl:failed-assert>
2279
+ </xsl:if>
2280
+ <xsl:if test="normalize-space(cbc:ID) = 'O'">
2281
+ <xsl:if test="not(exists(cbc:TaxExemptionReasonCode) and normalize-space(cbc:TaxExemptionReasonCode )!='' )">
2282
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-24">
2283
+ <xsl:attribute name="test">not((exists(cbc:TaxExemptionReasonCode) ) and (contains('VAT-OOS-SA ',cbc:TaxExemptionReasonCode)))</xsl:attribute>
2284
+ <svrl:text>[BR-KSA-24]-A VAT breakdown (BG-23) with VAT Category code (BT-118) 'Not subject to VAT' shall have a VAT exception reason code (BT-121)</svrl:text>
2285
+ <svrl:message-code>BR-KSA-24</svrl:message-code>
2286
+ <svrl:message-category>Business rules - Not subject to VAT (BR-KSA)</svrl:message-category>
2287
+ </svrl:failed-assert>
2288
+ </xsl:if>
2289
+ </xsl:if>
2290
+ <xsl:if test="normalize-space(cbc:ID) = 'E'">
2291
+
2292
+ <xsl:if test="not(exists(cbc:TaxExemptionReasonCode) and normalize-space(cbc:TaxExemptionReasonCode )!='' )">
2293
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-23">
2294
+ <xsl:attribute name="test">not(exists(cbc:TaxExemptionReasonCode) and (contains('VATEX-SA-29 VATEX-SA-29-7 VATEX-SA-30',upper-case(cbc:TaxExemptionReasonCode))))</xsl:attribute>
2295
+ <svrl:text>[BR-KSA-23]-A VAT breakdown (BG-23) with VAT Category code (BT-118) 'Exempt from VAT' shall have a VAT exemption reason code (BT-121).</svrl:text>
2296
+ <svrl:message-code>BR-KSA-23</svrl:message-code>
2297
+ <svrl:message-category>Business rules - Exempted from VAT (BR-KSA)</svrl:message-category>
2298
+ </svrl:failed-assert>
2299
+ </xsl:if>
2300
+ </xsl:if>
2301
+
2302
+ <xsl:if test="normalize-space(cbc:ID) = 'Z'">
2303
+ <xsl:if test="not(exists(cbc:TaxExemptionReasonCode) and normalize-space(cbc:TaxExemptionReasonCode )!='' )">
2304
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-69">
2305
+ <xsl:attribute name="test">not((exists(cbc:TaxExemptionReasonCode) ) and (contains('VATEX-SA-32 VATEX-SA-33 VATEX-SA-34-1 VATEX-SA-34-2 VATEX-SA-34-3 VATEX-SA-34-4 VATEX-SA-34-5 VATEX-SA-35 VATEX-SA-36 VATEX-SA-EDU VATEX-SA-HEA VATEX-SA-MLTRY VATEX-SA-DIPLOMAT',cbc:TaxExemptionReasonCode)) )</xsl:attribute>
2306
+ <svrl:text>[BR-KSA-69]-A VAT breakdown (BG-23) with VAT Category code (BT-118) 'Zero rated' shall have a VAT exception reason code (BT-121).</svrl:text>
2307
+ <svrl:message-code>BR-KSA-69</svrl:message-code>
2308
+ <svrl:message-category>Business rules - VAT zero rate (BR-KSA)</svrl:message-category>
2309
+ </svrl:failed-assert>
2310
+ </xsl:if>
2311
+ </xsl:if>
2312
+
2313
+
2314
+
2315
+ </schxslt:rule>
2316
+ <xsl:next-match>
2317
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e355')"/>
2318
+ </xsl:next-match>
2319
+ </xsl:otherwise>
2320
+ </xsl:choose>
2321
+ </xsl:template>
2322
+
2323
+ <xsl:template match="cac:* | cbc:*" priority="12" mode="d7e29">
2324
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2325
+ <xsl:choose>
2326
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e385']">
2327
+ <schxslt:rule pattern="d7e385">
2328
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:* | cbc:*" shadowed by preceding rule</xsl:comment>
2329
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2330
+ <xsl:attribute name="context">cac:* | cbc:*</xsl:attribute>
2331
+ </svrl:suppressed-rule>
2332
+ </schxslt:rule>
2333
+ <xsl:next-match>
2334
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2335
+ </xsl:next-match>
2336
+ </xsl:when>
2337
+ <xsl:otherwise>
2338
+ <xsl:next-match>
2339
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e385')"/>
2340
+ </xsl:next-match>
2341
+ </xsl:otherwise>
2342
+ </xsl:choose>
2343
+ </xsl:template>
2344
+ <xsl:template match="cbc:IssueDate | cbc:DueDate | cac:Delivery/cbc:ActualDeliveryDate | cac:BillingReference/cac:InvoiceDocumentReference/cbc:IssueDate | cac:InvoiceLine/cac:DocumentReference/cbc:IssueDate" priority="11" mode="d7e29">
2345
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2346
+ <xsl:choose>
2347
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e395']">
2348
+ <schxslt:rule pattern="d7e395">
2349
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cbc:IssueDate | cbc:DueDate | cac:Delivery/cbc:ActualDeliveryDate | cac:BillingReference/cac:InvoiceDocumentReference/cbc:IssueDate | cac:InvoiceLine/cac:DocumentReference/cbc:IssueDate" shadowed by preceding rule</xsl:comment>
2350
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2351
+ <xsl:attribute name="context">cbc:IssueDate | cbc:DueDate | cac:Delivery/cbc:ActualDeliveryDate | cac:BillingReference/cac:InvoiceDocumentReference/cbc:IssueDate | cac:InvoiceLine/cac:DocumentReference/cbc:IssueDate</xsl:attribute>
2352
+ </svrl:suppressed-rule>
2353
+ </schxslt:rule>
2354
+ <xsl:next-match>
2355
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2356
+ </xsl:next-match>
2357
+ </xsl:when>
2358
+ <xsl:otherwise>
2359
+ <schxslt:rule pattern="d7e395">
2360
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2361
+ <xsl:attribute name="context">cbc:IssueDate | cbc:DueDate | cac:Delivery/cbc:ActualDeliveryDate | cac:BillingReference/cac:InvoiceDocumentReference/cbc:IssueDate | cac:InvoiceLine/cac:DocumentReference/cbc:IssueDates</xsl:attribute>
2362
+ </svrl:fired-rule>
2363
+ <xsl:if test="not(string-length(.) = 10 and matches( string(.), '[0-9]{4}-[0-9]{2}-[0-9]{2}') )">
2364
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-01">
2365
+ <xsl:attribute name="test">(string-length(.) = 10 and (string(.) castable as xs:date))</xsl:attribute>
2366
+ <svrl:text>[BR-KSA-F-01]-A date MUST be formatted YYYY-MM-DD.</svrl:text>
2367
+ <svrl:message-code>BR-KSA-F-01</svrl:message-code>
2368
+ <svrl:message-category>KSA - formats (BR-KSA-F)</svrl:message-category>
2369
+ </svrl:failed-assert>
2370
+ </xsl:if>
2371
+ </schxslt:rule>
2372
+ <xsl:next-match>
2373
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e395')"/>
2374
+ </xsl:next-match>
2375
+ </xsl:otherwise>
2376
+ </xsl:choose>
2377
+ </xsl:template>
2378
+ <xsl:template match="cac:InvoiceLine/cac:DocumentReference/cbc:IssueTime" priority="11" mode="d7e29">
2379
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2380
+ <xsl:choose>
2381
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e395']">
2382
+ <schxslt:rule pattern="d7e395">
2383
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:InvoiceLine/cac:DocumentReference/cbc:IssueTime" shadowed by preceding rule</xsl:comment>
2384
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2385
+ <xsl:attribute name="context">cac:InvoiceLine/cac:DocumentReference/cbc:IssueTime</xsl:attribute>
2386
+ </svrl:suppressed-rule>
2387
+ </schxslt:rule>
2388
+ <xsl:next-match>
2389
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2390
+ </xsl:next-match>
2391
+ </xsl:when>
2392
+ <xsl:otherwise>
2393
+ <schxslt:rule pattern="d7e395">
2394
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2395
+ <xsl:attribute name="context">cac:InvoiceLine/cac:DocumentReference/cbc:IssueTime</xsl:attribute>
2396
+ </svrl:fired-rule>
2397
+ <xsl:if test="not(((string(.) castable as xs:time)))">
2398
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-05">
2399
+ <xsl:attribute name="test">(string-length(.) = 8 and (string(.) castable as xs:time))</xsl:attribute>
2400
+ <svrl:text>[BR-KSA-F-05]-Prepayment Issue Time (KSA-29) must be in the format: hh:mm:ss for time expressed in AST or hh:mm:ssZ for time expressed in UTC.(eg 19:20:30)</svrl:text>
2401
+ <svrl:message-code>BR-KSA-F-05</svrl:message-code>
2402
+ <svrl:message-category>KSA - formats (BR-KSA-F)</svrl:message-category>
2403
+ </svrl:failed-assert>
2404
+ </xsl:if>
2405
+ </schxslt:rule>
2406
+ <xsl:next-match>
2407
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e395')"/>
2408
+ </xsl:next-match>
2409
+ </xsl:otherwise>
2410
+ </xsl:choose>
2411
+ </xsl:template>
2412
+ <xsl:template match="cac:AllowanceCharge/cbc:ChargeIndicator | cac:InvoiceLine/cac:AllowanceCharge/cbc:ChargeIndicator" priority="10" mode="d7e29">
2413
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2414
+ <xsl:choose>
2415
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e395']">
2416
+ <schxslt:rule pattern="d7e395">
2417
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:AllowanceCharge/cbc:ChargeIndicator | cac:InvoiceLine/cac:AllowanceCharge/cbc:ChargeIndicator" shadowed by preceding rule</xsl:comment>
2418
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2419
+ <xsl:attribute name="context">cac:AllowanceCharge/cbc:ChargeIndicator | cac:InvoiceLine/cac:AllowanceCharge/cbc:ChargeIndicator</xsl:attribute>
2420
+ </svrl:suppressed-rule>
2421
+ </schxslt:rule>
2422
+ <xsl:next-match>
2423
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2424
+ </xsl:next-match>
2425
+ </xsl:when>
2426
+ <xsl:otherwise>
2427
+ <schxslt:rule pattern="d7e395">
2428
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2429
+ <xsl:attribute name="context">cac:AllowanceCharge/cbc:ChargeIndicator | cac:InvoiceLine/cac:AllowanceCharge/cbc:ChargeIndicator</xsl:attribute>
2430
+ </svrl:fired-rule>
2431
+ <xsl:if test="not((.) = false() or (.)=true())">
2432
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-F-02">
2433
+ <xsl:attribute name="test">(.) = false()</xsl:attribute>
2434
+ <svrl:text>[BR-KSA-F-02]-Allowance/Charge Indicator value MUST equal to 'false'/’True’ respectively.</svrl:text>
2435
+ <svrl:message-code>BR-KSA-F-02</svrl:message-code>
2436
+ <svrl:message-category>KSA - formats (BR-KSA-F)</svrl:message-category>
2437
+ </svrl:failed-assert>
2438
+ </xsl:if>
2439
+ </schxslt:rule>
2440
+ <xsl:next-match>
2441
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e395')"/>
2442
+ </xsl:next-match>
2443
+ </xsl:otherwise>
2444
+ </xsl:choose>
2445
+ </xsl:template>
2446
+ <xsl:template match="ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal[normalize-space(cac:TaxCategory/cbc:ID)!='O']/cbc:TaxableAmount | ubl:Invoice/cac:AllowanceCharge/cbc:Amount | ubl:Invoice/cac:AllowanceCharge/cbc:BaseAmount | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:LineExtensionAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:TaxExclusiveAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:TaxInclusiveAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:AllowanceTotalAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:ChargeTotalAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:PrepaidAmount | ubl:Invoice/cac:TaxTotal/cbc:TaxAmount | ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge/cbc:Amount | ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge/cbc:BaseAmount | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cbc:TaxAmount | ubl:Invoice/cac:InvoiceLine/cac:Price/cbc:PriceAmount | ubl:Invoice/cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:Amount | ubl:Invoice/cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:BaseAmount | ubl:Invoice/cac:InvoiceLine/cbc:InvoicedQuantity | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount "
2447
+ priority="9"
2448
+ mode="d7e29">
2449
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2450
+ <xsl:choose>
2451
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e395']">
2452
+ <schxslt:rule pattern="d7e395">
2453
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context ""ubl:Invoice/cac:AllowanceCharge/cbc:Amount | ubl:Invoice/cac:AllowanceCharge/cbc:BaseAmount | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:LineExtensionAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:TaxExclusiveAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:TaxInclusiveAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:AllowanceTotalAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:ChargeTotalAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:PrepaidAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:PayableRoundingAmount | ubl:Invoice/cac:TaxTotal/cbc:TaxAmount | ubl:Invoice/cac:InvoiceLine/cbc:LineExtensionAmount | ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge/cbc:Amount | ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge/cbc:BaseAmount | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cbc:TaxAmount | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cbc:RoundingAmount | ubl:Invoice/cac:InvoiceLine/cac:Price/cbc:PriceAmount | ubl:Invoice/cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:Amount | ubl:Invoice/cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:BaseAmount | ubl:Invoice/cac:InvoiceLine/cbc:InvoicedQuantity | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount" shadowed by preceding rule</xsl:comment>
2454
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2455
+ <xsl:attribute name="context">"ubl:Invoice/cac:AllowanceCharge/cbc:Amount | ubl:Invoice/cac:AllowanceCharge/cbc:BaseAmount | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:LineExtensionAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:TaxExclusiveAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:TaxInclusiveAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:AllowanceTotalAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:ChargeTotalAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:PrepaidAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:PayableRoundingAmount | ubl:Invoice/cac:TaxTotal/cbc:TaxAmount | ubl:Invoice/cac:InvoiceLine/cbc:LineExtensionAmount | ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge/cbc:Amount | ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge/cbc:BaseAmount | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cbc:TaxAmount | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cbc:RoundingAmount | ubl:Invoice/cac:InvoiceLine/cac:Price/cbc:PriceAmount | ubl:Invoice/cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:Amount | ubl:Invoice/cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:BaseAmount | ubl:Invoice/cac:InvoiceLine/cbc:InvoicedQuantity | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount</xsl:attribute>
2456
+ </svrl:suppressed-rule>
2457
+ </schxslt:rule>
2458
+ <xsl:next-match>
2459
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2460
+ </xsl:next-match>
2461
+ </xsl:when>
2462
+ <xsl:otherwise>
2463
+ <schxslt:rule pattern="d7e395">
2464
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2465
+ <xsl:attribute name="context">"ubl:Invoice/cac:AllowanceCharge/cbc:Amount | ubl:Invoice/cac:AllowanceCharge/cbc:BaseAmount | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount | ubl:Invoice/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:LineExtensionAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:TaxExclusiveAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:TaxInclusiveAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:AllowanceTotalAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:ChargeTotalAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:PrepaidAmount | ubl:Invoice/cac:LegalMonetaryTotal/cbc:PayableRoundingAmount | ubl:Invoice/cac:TaxTotal/cbc:TaxAmount | ubl:Invoice/cac:InvoiceLine/cbc:LineExtensionAmount | ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge/cbc:Amount | ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge/cbc:BaseAmount | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cbc:TaxAmount | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cbc:RoundingAmount | ubl:Invoice/cac:InvoiceLine/cac:Price/cbc:PriceAmount | ubl:Invoice/cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:Amount | ubl:Invoice/cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:BaseAmount | ubl:Invoice/cac:InvoiceLine/cbc:InvoicedQuantity | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount | ubl:Invoice/cac:InvoiceLine/cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount</xsl:attribute>
2466
+ </svrl:fired-rule>
2467
+ <xsl:if test="string-length(.) &gt; 0 and not((.) &gt;= 0)">
2468
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-F-04">
2469
+ <xsl:attribute name="test">number(.) &gt;= 0</xsl:attribute>
2470
+ <svrl:text>[BR-KSA-F-04]-All the document amounts and quantities must be positive.</svrl:text>
2471
+ <svrl:message-code>BR-KSA-F-04</svrl:message-code>
2472
+ <svrl:message-category>KSA - formats (BR-KSA-F)</svrl:message-category>
2473
+ </svrl:failed-assert>
2474
+ </xsl:if>
2475
+ </schxslt:rule>
2476
+ <xsl:next-match>
2477
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e395')"/>
2478
+ </xsl:next-match>
2479
+ </xsl:otherwise>
2480
+ </xsl:choose>
2481
+ </xsl:template>
2482
+ <xsl:template match="/ubl:Invoice" priority="8" mode="d7e29">
2483
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2484
+ <xsl:choose>
2485
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e416']">
2486
+ <schxslt:rule pattern="d7e416">
2487
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "/ubl:Invoice" shadowed by preceding rule</xsl:comment>
2488
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2489
+ <xsl:attribute name="context">/ubl:Invoice</xsl:attribute>
2490
+ </svrl:suppressed-rule>
2491
+ </schxslt:rule>
2492
+ <xsl:next-match>
2493
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2494
+ </xsl:next-match>
2495
+ </xsl:when>
2496
+ <xsl:otherwise>
2497
+ <schxslt:rule pattern="d7e416">
2498
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2499
+ <xsl:attribute name="context">/ubl:Invoice</xsl:attribute>
2500
+ </svrl:fired-rule>
2501
+ <xsl:if test="not(exists(./cbc:ProfileID) and (normalize-space(./cbc:ProfileID)) = 'reporting:1.0')">
2502
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-EN16931-01">
2503
+ <xsl:attribute name="test">exists(./cbc:ProfileID) and (normalize-space(./cbc:ProfileID)) = 'reporting:1.0'</xsl:attribute>
2504
+ <svrl:text>[BR-KSA-EN16931-01]-Business process (BT-23) must be "reporting:1.0".</svrl:text>
2505
+ <svrl:message-code>BR-KSA-EN16931-01</svrl:message-code>
2506
+ <svrl:message-category>KSA - EN16931 (BR-KSA-EN16931)</svrl:message-category>
2507
+ </svrl:failed-assert>
2508
+ </xsl:if>
2509
+ <xsl:if test="not(count(./cac:TaxTotal) &gt;= 1 and count(./cac:TaxTotal/cac:TaxSubtotal) &gt;= 1)">
2510
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-EN16931-08">
2511
+ <xsl:attribute name="test">count(./cac:TaxTotal) &gt;= 1 and count(./cac:TaxTotal/cac:TaxSubtotal) &gt;= 1</xsl:attribute>
2512
+ <svrl:text>[BR-KSA-EN16931-08]-Only one tax total (BG-22) with tax subtotals must be provided.</svrl:text>
2513
+ <svrl:message-code>BR-KSA-EN16931-08</svrl:message-code>
2514
+ <svrl:message-category>KSA - EN16931 (BR-KSA-EN16931)</svrl:message-category>
2515
+ </svrl:failed-assert>
2516
+ </xsl:if>
2517
+ </schxslt:rule>
2518
+ <xsl:next-match>
2519
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e416')"/>
2520
+ </xsl:next-match>
2521
+ </xsl:otherwise>
2522
+ </xsl:choose>
2523
+ </xsl:template>
2524
+ <xsl:template match="cbc:TaxCurrencyCode" priority="7" mode="d7e29">
2525
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2526
+ <xsl:choose>
2527
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e416']">
2528
+ <schxslt:rule pattern="d7e416">
2529
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cbc:TaxCurrencyCode" shadowed by preceding rule</xsl:comment>
2530
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2531
+ <xsl:attribute name="context">cbc:TaxCurrencyCode</xsl:attribute>
2532
+ </svrl:suppressed-rule>
2533
+ </schxslt:rule>
2534
+ <xsl:next-match>
2535
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2536
+ </xsl:next-match>
2537
+ </xsl:when>
2538
+ <xsl:otherwise>
2539
+ <schxslt:rule pattern="d7e416">
2540
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2541
+ <xsl:attribute name="context">cbc:TaxCurrencyCode</xsl:attribute>
2542
+ </svrl:fired-rule>
2543
+ <xsl:if test="not((normalize-space(upper-case(.))) = 'SAR')">
2544
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-EN16931-02">
2545
+ <xsl:attribute name="test">(normalize-space(upper-case(.))) = 'SAR'</xsl:attribute>
2546
+ <svrl:text>[BR-KSA-EN16931-02]-VAT accounting currency code (BT-6) must be SAR.</svrl:text>
2547
+ <svrl:message-code>BR-KSA-EN16931-02</svrl:message-code>
2548
+ <svrl:message-category>KSA - EN16931 (BR-KSA-EN16931)</svrl:message-category>
2549
+ </svrl:failed-assert>
2550
+ </xsl:if>
2551
+ <xsl:if test="not(count(../cac:TaxTotal) &gt;= 2 and count(../cac:TaxTotal) &lt;= 2 and count(../cac:TaxTotal/cac:TaxSubtotal) &gt;= 1)">
2552
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-EN16931-09">
2553
+ <xsl:attribute name="test">count(../cac:TaxTotal) &gt;= 2 and count(../cac:TaxTotal) &lt;= 2 and count(../cac:TaxTotal/cac:TaxSubtotal) &gt;= 1</xsl:attribute>
2554
+ <svrl:text>[BR-KSA-EN16931-09]-Only one tax total (BG-22) without tax subtotals must be provided when tax currency code is provided.</svrl:text>
2555
+ <svrl:message-code>BR-KSA-EN16931-09</svrl:message-code>
2556
+ <svrl:message-category>KSA - EN16931 (BR-KSA-EN16931)</svrl:message-category>
2557
+ </svrl:failed-assert>
2558
+ </xsl:if>
2559
+ </schxslt:rule>
2560
+ <xsl:next-match>
2561
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e416')"/>
2562
+ </xsl:next-match>
2563
+ </xsl:otherwise>
2564
+ </xsl:choose>
2565
+ </xsl:template>
2566
+ <xsl:template match="/ubl:Invoice/cac:AllowanceCharge[cbc:BaseAmount][/ubl:Invoice/cac:AllowanceCharge[cbc:Amount]] | /ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:BaseAmount][/ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:Amount]]" priority="6" mode="d7e29">
2567
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2568
+ <xsl:choose>
2569
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e416']">
2570
+ <schxslt:rule pattern="d7e416">
2571
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "/ubl:Invoice/cac:AllowanceCharge[cbc:BaseAmount][/ubl:Invoice/cac:AllowanceCharge[cbc:Amount]] | /ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:BaseAmount][/ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:Amount]]" shadowed by preceding rule</xsl:comment>
2572
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2573
+ <xsl:attribute name="context">/ubl:Invoice/cac:AllowanceCharge[cbc:BaseAmount][/ubl:Invoice/cac:AllowanceCharge[cbc:Amount]] | /ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:BaseAmount][/ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:Amount]]</xsl:attribute>
2574
+ </svrl:suppressed-rule>
2575
+ </schxslt:rule>
2576
+ <xsl:next-match>
2577
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2578
+ </xsl:next-match>
2579
+ </xsl:when>
2580
+ <xsl:otherwise>
2581
+ <schxslt:rule pattern="d7e416">
2582
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2583
+ <xsl:attribute name="context">/ubl:Invoice/cac:AllowanceCharge[cbc:BaseAmount][/ubl:Invoice/cac:AllowanceCharge[cbc:Amount]] | /ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:BaseAmount][/ubl:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:Amount]]</xsl:attribute>
2584
+ </svrl:fired-rule>
2585
+ <xsl:if test="string-length(./cbc:Amount) &gt; 0 and string-length(./cbc:BaseAmount) &gt; 0 and not ( format-number(./cbc:Amount,'#.00') = format-number(( floor((((./cbc:BaseAmount * ./cbc:MultiplierFactorNumeric) div 100) * 100 + 0.5)) div 100), '#.00'))">
2586
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-EN16931-03">
2587
+ <xsl:attribute name="test">xs:decimal(./cbc:Amount) = (xs:decimal(./cbc:BaseAmount) * xs:decimal(./cbc:MultiplierFactorNumeric) div 100)</xsl:attribute>
2588
+ <svrl:text>[BR-KSA-EN16931-03]-Allowance/Charge amount (BT-92, BT-99, BT-136, BT-141) must equal base amount (BT-93, BT-100, BT-137, BT-142) * percentage (BT-94, BT-101, BT-138, BT-143) / 100 if base amount and percentage exists.</svrl:text>
2589
+ <svrl:message-code>BR-KSA-EN16931-03</svrl:message-code>
2590
+ <svrl:message-category>KSA - EN16931 (BR-KSA-EN16931)</svrl:message-category>
2591
+ </svrl:failed-assert>
2592
+ </xsl:if>
2593
+ </schxslt:rule>
2594
+ <xsl:next-match>
2595
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e416')"/>
2596
+ </xsl:next-match>
2597
+ </xsl:otherwise>
2598
+ </xsl:choose>
2599
+ </xsl:template>
2600
+ <xsl:template match="ubl:Invoice/cac:AllowanceCharge/cbc:BaseAmount | cac:InvoiceLine/cac:AllowanceCharge/cbc:BaseAmount" priority="5" mode="d7e29">
2601
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2602
+ <xsl:choose>
2603
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e416']">
2604
+ <schxslt:rule pattern="d7e416">
2605
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:AllowanceCharge/cbc:BaseAmount | cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:BaseAmount" shadowed by preceding rule</xsl:comment>
2606
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2607
+ <xsl:attribute name="context">cac:AllowanceCharge/cbc:BaseAmount | cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:BaseAmount</xsl:attribute>
2608
+ </svrl:suppressed-rule>
2609
+ </schxslt:rule>
2610
+ <xsl:next-match>
2611
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2612
+ </xsl:next-match>
2613
+ </xsl:when>
2614
+ <xsl:otherwise>
2615
+ <schxslt:rule pattern="d7e416">
2616
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2617
+ <xsl:attribute name="context">cac:AllowanceCharge/cbc:BaseAmount | cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:BaseAmount</xsl:attribute>
2618
+ </svrl:fired-rule>
2619
+ <xsl:if test="not(exists(../cbc:MultiplierFactorNumeric))">
2620
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-EN16931-05">
2621
+ <xsl:attribute name="test">exists(../cbc:MultiplierFactorNumeric)</xsl:attribute>
2622
+ <svrl:text>[BR-KSA-EN16931-05]-Allowance/Charge percentage (BT-94, BT-101, BT-138, BT-143) must be provided when the allowance/Charge base amount (BT-93, BT-100, BT-137, BT-142) is provided.</svrl:text>
2623
+ <svrl:message-code>BR-KSA-EN16931-05</svrl:message-code>
2624
+ <svrl:message-category>KSA - EN16931 (BR-KSA-EN16931)</svrl:message-category>
2625
+ </svrl:failed-assert>
2626
+ </xsl:if>
2627
+ </schxslt:rule>
2628
+ <xsl:next-match>
2629
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e416')"/>
2630
+ </xsl:next-match>
2631
+ </xsl:otherwise>
2632
+ </xsl:choose>
2633
+ </xsl:template>
2634
+ <xsl:template match="cac:AllowanceCharge/cbc:MultiplierFactorNumeric | cac:InvoiceLine/cac:AllowanceCharge/cbc:MultiplierFactorNumeric" priority="4" mode="d7e29">
2635
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2636
+ <xsl:choose>
2637
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e416']">
2638
+ <schxslt:rule pattern="d7e416">
2639
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:AllowanceCharge/cbc:MultiplierFactorNumeric | cac:InvoiceLine/cac:AllowanceCharge/cbc:MultiplierFactorNumeric" shadowed by preceding rule</xsl:comment>
2640
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2641
+ <xsl:attribute name="context">cac:AllowanceCharge/cbc:MultiplierFactorNumeric | cac:InvoiceLine/cac:AllowanceCharge/cbc:MultiplierFactorNumeric</xsl:attribute>
2642
+ </svrl:suppressed-rule>
2643
+ </schxslt:rule>
2644
+ <xsl:next-match>
2645
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2646
+ </xsl:next-match>
2647
+ </xsl:when>
2648
+ <xsl:otherwise>
2649
+ <schxslt:rule pattern="d7e416">
2650
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2651
+ <xsl:attribute name="context">cac:AllowanceCharge/cbc:MultiplierFactorNumeric | cac:InvoiceLine/cac:AllowanceCharge/cbc:MultiplierFactorNumeric</xsl:attribute>
2652
+ </svrl:fired-rule>
2653
+ <xsl:if test="not(exists(../cbc:BaseAmount))">
2654
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-EN16931-04">
2655
+ <xsl:attribute name="test">exists(../cbc:BaseAmount)</xsl:attribute>
2656
+ <svrl:text>[BR-KSA-EN16931-04]-Allowance/Charge base amount (BT-93, BT-100, BT-137, BT-142) must be provided when allowance/Charge percentage (BT-94, BT-101,BT-138, BT-143) is provided.</svrl:text>
2657
+ <svrl:message-code>BR-KSA-EN16931-04</svrl:message-code>
2658
+ <svrl:message-category>KSA - EN16931 (BR-KSA-EN16931)</svrl:message-category>
2659
+ </svrl:failed-assert>
2660
+ </xsl:if>
2661
+ </schxslt:rule>
2662
+ <xsl:next-match>
2663
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e416')"/>
2664
+ </xsl:next-match>
2665
+ </xsl:otherwise>
2666
+ </xsl:choose>
2667
+ </xsl:template>
2668
+ <xsl:template match="cac:InvoiceLine/cac:Price/cac:AllowanceCharge" priority="3" mode="d7e29">
2669
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2670
+ <xsl:choose>
2671
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e416']">
2672
+ <schxslt:rule pattern="d7e416">
2673
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:InvoiceLine/cac:Price/cac:AllowanceCharge" shadowed by preceding rule</xsl:comment>
2674
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2675
+ <xsl:attribute name="context">cac:InvoiceLine/cac:Price/cac:AllowanceCharge</xsl:attribute>
2676
+ </svrl:suppressed-rule>
2677
+ </schxslt:rule>
2678
+ <xsl:next-match>
2679
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2680
+ </xsl:next-match>
2681
+ </xsl:when>
2682
+ <xsl:otherwise>
2683
+ <schxslt:rule pattern="d7e416">
2684
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2685
+ <xsl:attribute name="context">cac:InvoiceLine/cac:Price/cac:AllowanceCharge</xsl:attribute>
2686
+ </svrl:fired-rule>
2687
+ <xsl:if test="not((cbc:ChargeIndicator) = false() or (cbc:ChargeIndicator) = true())">
2688
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-EN16931-06">
2689
+ <xsl:attribute name="test">(cbc:ChargeIndicator) = false()</xsl:attribute>
2690
+ <svrl:text>[BR-KSA-EN16931-06]-Charge on price level (BG-29) is allowed. The value of Indicator should be ' True'.</svrl:text>
2691
+ <svrl:message-code>BR-KSA-EN16931-06</svrl:message-code>
2692
+ <svrl:message-category>KSA - EN16931 (BR-KSA-EN16931)</svrl:message-category>
2693
+ </svrl:failed-assert>
2694
+ </xsl:if>
2695
+ </schxslt:rule>
2696
+ <xsl:next-match>
2697
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e416')"/>
2698
+ </xsl:next-match>
2699
+ </xsl:otherwise>
2700
+ </xsl:choose>
2701
+ </xsl:template>
2702
+ <xsl:template match="cac:InvoiceLine" priority="2" mode="d7e29">
2703
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2704
+ <xsl:choose>
2705
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e416']">
2706
+ <schxslt:rule pattern="d7e416">
2707
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:InvoiceLine" shadowed by preceding rule</xsl:comment>
2708
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2709
+ <xsl:attribute name="context">cac:InvoiceLine</xsl:attribute>
2710
+ </svrl:suppressed-rule>
2711
+ </schxslt:rule>
2712
+ <xsl:next-match>
2713
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2714
+ </xsl:next-match>
2715
+ </xsl:when>
2716
+ <xsl:otherwise>
2717
+ <schxslt:rule pattern="d7e416">
2718
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2719
+ <xsl:attribute name="context">cac:InvoiceLine</xsl:attribute>
2720
+
2721
+ </svrl:fired-rule>
2722
+ <xsl:if test="count((.)) &gt; 0 and not ( ( ( not(exists(cac:Price/cbc:BaseQuantity)) and xs:decimal(cbc:LineExtensionAmount) = round( (( (floor((xs:decimal(cbc:InvoicedQuantity) * xs:decimal(cac:Price/cbc:PriceAmount) ) * 10 * 10 *10 )div 10 + 0.00000000001) ) div 100 )+ sum((cac:AllowanceCharge[cbc:ChargeIndicator=true()]/xs:decimal(cbc:Amount))) - sum((cac:AllowanceCharge[cbc:ChargeIndicator=false()]/xs:decimal(cbc:Amount))),2) +0.01) ) or ( ( not(exists(cac:Price/cbc:BaseQuantity)) and xs:decimal(cbc:LineExtensionAmount) = round( (( (floor((xs:decimal(cbc:InvoicedQuantity) * xs:decimal(cac:Price/cbc:PriceAmount) ) * 10 * 10 *10 )div 10 + 0.00000000001) ) div 100 )+ sum((cac:AllowanceCharge[cbc:ChargeIndicator=true()]/xs:decimal(cbc:Amount))) - sum((cac:AllowanceCharge[cbc:ChargeIndicator=false()]/xs:decimal(cbc:Amount))),2) -0.01) ) or ( ( not(exists(cac:Price/cbc:BaseQuantity)) and xs:decimal(cbc:LineExtensionAmount) = round( (( (floor((xs:decimal(cbc:InvoicedQuantity) * xs:decimal(cac:Price/cbc:PriceAmount) ) * 10 * 10 *10 )div 10 + 0.00000000001) ) div 100 )+ sum((cac:AllowanceCharge[cbc:ChargeIndicator=true()]/xs:decimal(cbc:Amount))) - sum((cac:AllowanceCharge[cbc:ChargeIndicator=false()]/xs:decimal(cbc:Amount))),2) ) ) or ( exists(cac:Price/cbc:BaseQuantity) and xs:decimal(cbc:LineExtensionAmount) = round(( (floor((xs:decimal(cbc:InvoicedQuantity) * (xs:decimal(cac:Price/cbc:PriceAmount) div xs:decimal(cac:Price/cbc:BaseQuantity)) ) * 10 * 10 * 10) div 10 + 0.00000000001 ) div 100 ) + sum((cac:AllowanceCharge[cbc:ChargeIndicator=true()]/xs:decimal(cbc:Amount))) - sum((cac:AllowanceCharge[cbc:ChargeIndicator=false()]/xs:decimal(cbc:Amount))) ,2 ) ) or ( exists(cac:Price/cbc:BaseQuantity) and xs:decimal(cbc:LineExtensionAmount) = round(( (floor((xs:decimal(cbc:InvoicedQuantity) * (xs:decimal(cac:Price/cbc:PriceAmount) div xs:decimal(cac:Price/cbc:BaseQuantity)) ) * 10 * 10 * 10) div 10 + 0.00000000001 ) div 100 ) + sum((cac:AllowanceCharge[cbc:ChargeIndicator=true()]/xs:decimal(cbc:Amount))) - sum((cac:AllowanceCharge[cbc:ChargeIndicator=false()]/xs:decimal(cbc:Amount))) ,2 ) +0.01) or ( exists(cac:Price/cbc:BaseQuantity) and xs:decimal(cbc:LineExtensionAmount) = round(( (floor((xs:decimal(cbc:InvoicedQuantity) * (xs:decimal(cac:Price/cbc:PriceAmount) div xs:decimal(cac:Price/cbc:BaseQuantity)) ) * 10 * 10 * 10) div 10 + 0.00000000001 ) div 100 ) + sum((cac:AllowanceCharge[cbc:ChargeIndicator=true()]/xs:decimal(cbc:Amount))) - sum((cac:AllowanceCharge[cbc:ChargeIndicator=false()]/xs:decimal(cbc:Amount))) ,2 ) -0.01) )">
2723
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-EN16931-11">
2724
+ <xsl:attribute name="test">((exists(cac:Price/cbc:BaseQuantity) and xs:decimal(cbc:LineExtensionAmount) = xs:decimal(cbc:InvoicedQuantity) * ((xs:decimal(cac:Price/cbc:PriceAmount) div xs:decimal(cac:Price/cbc:BaseQuantity)) - xs:decimal(sum(cac:Price/cac:AllowanceCharge/cbc:Amount))))) or ((not(exists(cac:Price/cbc:BaseQuantity)) and xs:decimal(cbc:LineExtensionAmount) = xs:decimal(cbc:InvoicedQuantity) * xs:decimal(cac:Price/cbc:PriceAmount) - xs:decimal(sum(cac:Price/cac:AllowanceCharge/cbc:Amount))))</xsl:attribute>
2725
+ <svrl:text>[BR-KSA-EN16931-11]-Invoice line net amount (BT-131) must equal (Invoiced quantity (BT-129) * (Item net price (BT-146) / item price base quantity (BT-149))-) + Sum of invoice line charge amount (BT-141) - Sum of invoice line allowance amount (BT-136).</svrl:text>
2726
+ <svrl:message-code>BR-KSA-EN16931-11</svrl:message-code>
2727
+ <svrl:message-category>KSA - EN16931 (BR-KSA-EN16931)</svrl:message-category>
2728
+ </svrl:failed-assert>
2729
+ </xsl:if>
2730
+ <xsl:if test="exists(cac:Price/cbc:BaseQuantity/@unitCode) and string-length(cac:Price/cbc:BaseQuantity/@unitCode) &gt; 127">
2731
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="warning" id="BR-KSA-F-06-C21">
2732
+ <xsl:attribute name="test">exists(cac:InvoiceLine/cac:Price/cbc:BaseQuantity/@unitCode) and string-length(cac:InvoiceLine/cac:Price/cbc:BaseQuantity/@unitCode) &gt; 127
2733
+ </xsl:attribute>
2734
+ <svrl:text>[BR-KSA-F-06-C21] - Field character limits for Item price base quantity unit code field (BT-150) have not been met. The maximum limit is 127 characters.
2735
+ </svrl:text>
2736
+ <svrl:message-code>BR-KSA-F-06-C21</svrl:message-code>
2737
+ <svrl:message-category>KSA - business rules (BR-KSA)</svrl:message-category>
2738
+ </svrl:failed-assert>
2739
+ </xsl:if>
2740
+ </schxslt:rule>
2741
+ <xsl:next-match>
2742
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e416')"/>
2743
+ </xsl:next-match>
2744
+ </xsl:otherwise>
2745
+ </xsl:choose>
2746
+ </xsl:template>
2747
+ <xsl:template match="cac:InvoiceLine/cac:Price/cbc:BaseQuantity" priority="1" mode="d7e29">
2748
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2749
+ <xsl:choose>
2750
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e416']">
2751
+ <schxslt:rule pattern="d7e416">
2752
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:InvoiceLine/cac:Price/cbc:BaseQuantity" shadowed by preceding rule</xsl:comment>
2753
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2754
+ <xsl:attribute name="context">cac:InvoiceLine/cac:Price/cbc:BaseQuantity</xsl:attribute>
2755
+ </svrl:suppressed-rule>
2756
+ </schxslt:rule>
2757
+ <xsl:next-match>
2758
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2759
+ </xsl:next-match>
2760
+ </xsl:when>
2761
+ <xsl:otherwise>
2762
+ <schxslt:rule pattern="d7e416">
2763
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2764
+ <xsl:attribute name="context">cac:InvoiceLine/cac:Price/cbc:BaseQuantity</xsl:attribute>
2765
+ </svrl:fired-rule>
2766
+ <xsl:if test="string-length(.) &gt; 0 and not(number((.)) &gt; 0)">
2767
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-EN16931-12">
2768
+ <xsl:attribute name="test">number((.)) &gt; 0</xsl:attribute>
2769
+ <svrl:text>[BR-KSA-EN16931-12]-Base quantity (BT-149) must be a positive number above zero.</svrl:text>
2770
+ <svrl:message-code>BR-KSA-EN16931-12</svrl:message-code>
2771
+ <svrl:message-category>KSA - EN16931 (BR-KSA-EN16931)</svrl:message-category>
2772
+ </svrl:failed-assert>
2773
+ </xsl:if>
2774
+ </schxslt:rule>
2775
+ <xsl:next-match>
2776
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e416')"/>
2777
+ </xsl:next-match>
2778
+ </xsl:otherwise>
2779
+ </xsl:choose>
2780
+ </xsl:template>
2781
+ <xsl:template match="cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:BaseAmount" priority="0" mode="d7e29">
2782
+ <xsl:param name="schxslt:patterns-matched" as="xs:string*"/>
2783
+ <xsl:choose>
2784
+ <xsl:when test="$schxslt:patterns-matched[. = 'd7e474']">
2785
+ <schxslt:rule pattern="d7e474">
2786
+ <xsl:comment xmlns:svrl="http://purl.oclc.org/dsdl/svrl">WARNING: Rule for context "cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:BaseAmount" shadowed by preceding rule</xsl:comment>
2787
+ <svrl:suppressed-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2788
+ <xsl:attribute name="context">cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:BaseAmount</xsl:attribute>
2789
+ </svrl:suppressed-rule>
2790
+ </schxslt:rule>
2791
+ <xsl:next-match>
2792
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="$schxslt:patterns-matched"/>
2793
+ </xsl:next-match>
2794
+ </xsl:when>
2795
+ <xsl:otherwise>
2796
+ <schxslt:rule pattern="d7e474">
2797
+ <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
2798
+ <xsl:attribute name="context">cac:InvoiceLine/cac:Price/cac:AllowanceCharge/cbc:BaseAmount</xsl:attribute>
2799
+ </svrl:fired-rule>
2800
+ <xsl:if test="not(xs:decimal(../../cbc:PriceAmount) = xs:decimal(.) - xs:decimal(../cbc:Amount))">
2801
+ <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" location="{schxslt:location(.)}" flag="error" id="BR-KSA-EN16931-07">
2802
+ <xsl:attribute name="test">xs:decimal(../../cbc:PriceAmount) = xs:decimal(.) - xs:decimal(../cbc:Amount)</xsl:attribute>
2803
+ <svrl:text>[BR-KSA-EN16931-07]-Item net price (BT-146) must equal (Gross price (BT-148) - Allowance amount (BT-147)) when gross price is provided.</svrl:text>
2804
+ <svrl:message-code>BR-KSA-EN16931-07</svrl:message-code>
2805
+ <svrl:message-category>KSA - EN16931 (BR-KSA-EN16931)</svrl:message-category>
2806
+ </svrl:failed-assert>
2807
+ </xsl:if>
2808
+ </schxslt:rule>
2809
+ <xsl:next-match>
2810
+ <xsl:with-param name="schxslt:patterns-matched" as="xs:string*" select="($schxslt:patterns-matched, 'd7e474')"/>
2811
+ </xsl:next-match>
2812
+ </xsl:otherwise>
2813
+ </xsl:choose>
2814
+ </xsl:template>
2815
+ <xsl:function name="schxslt:location" as="xs:string">
2816
+ <xsl:param name="node" as="node()"/>
2817
+ <xsl:variable name="segments" as="xs:string*">
2818
+ <xsl:for-each select="($node/ancestor-or-self::node())">
2819
+ <xsl:variable name="position">
2820
+ <xsl:number level="single"/>
2821
+ </xsl:variable>
2822
+ <xsl:choose>
2823
+ <xsl:when test=". instance of element()">
2824
+ <xsl:value-of select="concat('Q{', namespace-uri(.), '}', local-name(.), '[', $position, ']')"/>
2825
+ </xsl:when>
2826
+ <xsl:when test=". instance of attribute()">
2827
+ <xsl:value-of select="concat('@Q{', namespace-uri(.), '}', local-name(.))"/>
2828
+ </xsl:when>
2829
+ <xsl:when test=". instance of processing-instruction()">
2830
+ <xsl:value-of select="concat('processing-instruction(&#34;', name(.), '&#34;)[', $position, ']')"/>
2831
+ </xsl:when>
2832
+ <xsl:when test=". instance of comment()">
2833
+ <xsl:value-of select="concat('comment()[', $position, ']')"/>
2834
+ </xsl:when>
2835
+ <xsl:when test=". instance of text()">
2836
+ <xsl:value-of select="concat('text()[', $position, ']')"/>
2837
+ </xsl:when>
2838
+ <xsl:otherwise/>
2839
+ </xsl:choose>
2840
+ </xsl:for-each>
2841
+ </xsl:variable>
2842
+ <xsl:value-of select="concat('/', string-join($segments, '/'))"/>
2843
+ </xsl:function>
2844
+ </xsl:transform>