message_1-input.xml
<?xml version="1.0"?>
<products>
<product
id="p1" stock="4"/>
</products>
message_1-stylesheet.xsl
<?xml version="1.0"?>
<xsl:stylesheet
version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable
name="x" select="products/product"/>
<xsl:output
indent="yes"/>
<xsl:template
match="/">
<products>
<product>
<xsl:attribute
name="id" select="$x/@id"/>
<xsl:attribute
name="stock" select="$x/@stock"/>
<xsl:if
test="not($x/@stock)">
<xsl:message
terminate="yes">Stock attribute is missing.</xsl:message>
</xsl:if>
</product>
</products>
</xsl:template>
</xsl:stylesheet>
message_1-output.xml
<?xml version="1.0" encoding="UTF-8"?>
<products>
<product
id="p1" stock="4"/>
</products>
The xsl:message element with terminate="yes" stops the transformation. Can also be used for debugging to write out content of variables, etc.
Updated 2009-03-19