<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:java="http://xml.apache.org/xslt/java"
 		exclude-result-prefixes="java"
 		version="1.0">

	<xsl:template match="/">
		<xsl:variable name="forms">
			<xsl:for-each select=".//W/M/FORM">
				<xsl:copy-of select='.'/>
			</xsl:for-each>
		</xsl:variable>
		<xsl:for-each select="java:mydistinct.distinct($forms)">
			<xsl:sort select="number(java:mysort.mysortvalue(string(.), string('1')))" data-type="number"/>
			<xsl:sort select="number(java:mysort.mysortvalue(string(.), string('2')))" data-type="number"/>
			<xsl:copy-of select="."/>
		</xsl:for-each>
	</xsl:template>

</xsl:stylesheet>