<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:protolsl="http://dret.net/xmlns/protolsl/">
	<xsl:output method="text"/>
	<xsl:param name="lsl" select="'blinks+addresses.lsl'"/>
	<xsl:template match="/">
		<xsl:for-each select="descendant::*[@xlink:type eq 'extended']">
			<xsl:variable name="resources" select="./*[@xlink:type = ('resource', 'locator')]"/>
			<xsl:variable name="link-count" select="position()"/>
			<xsl:for-each select="document($lsl)//resource">
				<xsl:if test="count($resources[current()/@type = tokenize(@protolsl:type, '\s+')]) &lt; ( if ( exists(@minOccurs) ) then @minOccurs else 0 ) or count($resources[current()/@type = tokenize(@protolsl:type, '\s+')]) > ( if ( exists(@maxOccurs) ) then @maxOccurs else 999 )">
					<xsl:message>
						<xsl:value-of select="concat('Wrong number of &quot;', @type, '&quot; resources in link #', $link-count)"/>
					</xsl:message>
				</xsl:if>
			</xsl:for-each>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>
