<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
	Native Xslt-Regeln - Version 1.0
	für XSLT-Prüfung der ZKA-konformen Belegung von camt XML-Nachrichten gemäß Namensraum (ns prefix)
-->
<xsl:stylesheet version="1.0" xmlns:camt="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02" xmlns:iso="http://purl.oclc.org/dsdl/schematron" xmlns:sch="http://www.ascc.net/xml/schematron" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" camt:dummy-for-xmlns="" xsi:dummy-for-xmlns="">
	<xsl:output method="text" encoding="ISO-8859-1"/>
	<xsl:template match="node()" mode="path">
		<xsl:for-each select="ancestor-or-self::*">
			<xsl:text>/</xsl:text>
			<xsl:value-of select="name(.)"/>
			<xsl:if test="preceding-sibling::*[name(.)=name(current())] or following-sibling::*[name(.)=name(current())]">
				<xsl:text>[</xsl:text>
				<xsl:value-of select="count(preceding-sibling::*[name(.)=name(current())])+1"/>
				<xsl:text>]</xsl:text>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="@*|node()">
		<xsl:apply-templates select="@*|node()"/>
	</xsl:template>
	<!--RULE -->
	<xsl:template match="/">
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="contains(camt:Document/@xsi:schemaLocation,'urn:iso:std:iso:20022:tech:xsd:camt.054.001.02')"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00000: Message Root of camt.054.001.02 is missing&#10;</xsl:otherwise>
		</xsl:choose>
		<xsl:apply-templates select="@*|*|comment()|processing-instruction()"/>
	</xsl:template>
	<!--RULE -->
	<xsl:template match="camt:Document">
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:BkToCstmrDbtCdtNtfctn/camt:Ntfctn)=1"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00012: Exactly 1 Ntfctn should be used&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:BkToCstmrDbtCdtNtfctn/camt:GrpHdr/camt:MsgRcpt/camt:Id/camt:PrvtId)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00035: MsgRcpt/Id/PrvtId should not be used&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:BkToCstmrDbtCdtNtfctn/camt:GrpHdr/camt:MsgPgntn"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00036: MsgPgntn is mandatory&#10;</xsl:otherwise>
		</xsl:choose>
		<xsl:apply-templates select="@*|*|comment()|processing-instruction()"/>
	</xsl:template>
	<!--RULE -->
	<xsl:template match="camt:Ntfctn">
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:ElctrncSeqNb"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00001: ElctrncSeqNb is mandatory&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:CpyDplctInd)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00002: Ntfctn/CpyDplctInd should not be used&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:Acct/camt:Svcr"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00020: Acct/Svcr is mandatory&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:TxsSummry)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00003: TxsSummry should not be used&#10;</xsl:otherwise>
		</xsl:choose>
		<xsl:apply-templates select="@*|*|comment()|processing-instruction()"/>
	</xsl:template>
	<!--RULE -->
	<xsl:template match="camt:Acct/camt:Svcr">
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:FinInstnId/camt:BIC"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00014: Svcr/FinInstnId/BIC is mandatory&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:FinInstnId/camt:Othr/camt:Id"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00015: Svcr/FinInstnId/Othr/Id must be used with a VAT id&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:FinInstnId/camt:Othr/camt:Issr='UmsStId'"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00016: Svcr/FinInstnId/Othr/Issr must be 'UmsStId'&#10;</xsl:otherwise>
		</xsl:choose>
		<xsl:apply-templates select="@*|*|comment()|processing-instruction()"/>
	</xsl:template>
	<!--RULE -->
	<xsl:template match="camt:AmtDtls">
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:InstdAmt/camt:CcyXchg)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00007: InstdAmt/CcyXchg should not be used&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:TxAmt/camt:Amt[@Ccy = ../../../../../../camt:Acct/camt:Ccy]"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00010: TxDtls/AmtDtls/TxAmt should be in account currency (Ntfctn/Acct/Ccy)&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:TxAmt/camt:CcyXchg)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00008: TxAmt/CcyXchg should not be used&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:AnncdPstngAmt/camt:CcyXchg)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00009: AnncdPstngAmt/CcyXchg should not be used&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:PrtryAmt)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00011: PrtryAmt should not be used&#10;</xsl:otherwise>
		</xsl:choose>
		<xsl:apply-templates select="@*|*|comment()|processing-instruction()"/>
	</xsl:template>
	<!--RULE -->
	<xsl:template match="camt:TxDtls">
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:BkTxCd"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00022: BkTxCd must be set on TxDtls level&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:BkTxCd/camt:Prtry"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00023: BkTxCd/Prtry is mandatory&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:BkTxCd/camt:Prtry/camt:Issr"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00024: BkTxCd/Prtry/Issr is mandatory&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:BkTxCd/camt:Prtry/camt:Issr='ZKA'"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00025: BkTxCd/Prtry/Issr must be set to 'ZKA'&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="string-length(camt:BkTxCd/camt:Prtry/camt:Cd) &gt;= 8 "/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00027: BkTxCd/Prtry/Cd should be of format Nsss+ggg[+pppppppppp]&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="string-length(camt:BkTxCd/camt:Prtry/camt:Cd) &lt;= 19 "/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00028: BkTxCd/Prtry/Cd should be of format Nsss+ggg[+pppppppppp]&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="substring(camt:BkTxCd/camt:Prtry/camt:Cd, 1, 1) = 'N'"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00029: BkTxCd/Prtry/Cd should be of format Nsss+ggg[+pppppppppp]&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="substring(camt:BkTxCd/camt:Prtry/camt:Cd, 5, 1) = '+' "/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00030: BkTxCd/Prtry/Cd should be of format Nsss+ggg[+pppppppppp]&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="string-length(camt:BkTxCd/camt:Prtry/camt:Cd) = 8 or substring(camt:BkTxCd/camt:Prtry/camt:Cd, 9, 1) = '+' "/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00031: BkTxCd/Prtry/Cd should be of format Nsss+ggg[+pppppppppp]&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:RltdRmtInf)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00032: RltdRmtInf should not be used&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:RltdDts)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00033: RltdDts should not be used&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:AddtlTxInf)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00034: AddtlTxInf should not be used&#10;</xsl:otherwise>
		</xsl:choose>
		<xsl:apply-templates select="@*|*|comment()|processing-instruction()"/>
	</xsl:template>
	<!--RULE -->
	<xsl:template match="camt:MsgPgntn">
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:PgNb='1'"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00037: Page number should be 1&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="string(camt:LastPgInd)='true'"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00038: Last page indidcator should be set to 'true'&#10;</xsl:otherwise>
		</xsl:choose>
		<xsl:apply-templates select="@*|*|comment()|processing-instruction()"/>
	</xsl:template>
	<!--RULE -->
	<xsl:template match="camt:BkTxCd/camt:Prtry">
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:Issr='ZKA'"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00039: Issr should be set to 'ZKA'&#10;</xsl:otherwise>
		</xsl:choose>
		<xsl:apply-templates select="@*|*|comment()|processing-instruction()"/>
	<!--RULE -->
	</xsl:template>
	<!--RULE -->
	<xsl:template match="camt:Ntry">
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:Amt[@Ccy = ../../camt:Acct/camt:Ccy]"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00040: Amt should be in account currency&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:BookgDt"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00041: BookgDt is mandatory&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:ValDt"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00042: ValDt is mandatory&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:AcctSvcrRef"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00043: AcctSvcrRef is mandatory&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:BkTxCd/camt:*) = 0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00046: BkTxCd must be set on TxDtls level, use an empty tag on Ntry level&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:ComssnWvrInd)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00047: ComssnWvrInd should not be used&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:AmtDtls)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00048: AmtDtls should be set on transaction level&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:Intrst)=0"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00049: Intrst should not be used&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="camt:NtryDtls/camt:TxDtls"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00044: TxDtls is mandatory&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:NtryDtls/camt:TxDtls) = 1 or count(camt:NtryDtls/camt:Btch/camt:NbOfTxs) = 0 or count(camt:NtryDtls/camt:TxDtls) = camt:NtryDtls/camt:Btch/camt:NbOfTxs"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00045: Number of TxDtls must be either 1 or equal to Btch/NbOfTxs&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:NtryDtls/camt:TxDtls/camt:AmtDtls) = 0 or count(camt:NtryDtls/camt:TxDtls/camt:AmtDtls) = count(camt:NtryDtls/camt:TxDtls/camt:AmtDtls/camt:TxAmt)"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00050: AmtDtls/TxAmt is mandatory for every TxDtls if AmtDtls is used&#10;</xsl:otherwise>
		</xsl:choose>
		<!--ASSERT -->
		<xsl:choose>
			<xsl:when test="count(camt:NtryDtls/camt:TxDtls/camt:AmtDtls) = 0 or sum(camt:NtryDtls/camt:TxDtls/camt:AmtDtls/camt:TxAmt) = camt:Amt"/>
			<xsl:otherwise>
				<xsl:apply-templates select="." mode="path"/> ZKA-00051: Sum of all TxDtls/AmtDtls/TxAmt must be equal to this entry's amount&#10;</xsl:otherwise>
		</xsl:choose>
		<xsl:apply-templates select="@*|*|comment()|processing-instruction()"/>
	</xsl:template>
</xsl:stylesheet>

