<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<!-- These are for testing the stylesheet outside of DirXML so things are pretty to look at -->
	<xsl:strip-space elements="*"/>
	<xsl:preserve-space elements="value component"/>
	<xsl:output indent="yes" method="xml"/>
	<!-- identity transform for everything we don't want to mess with -->
	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="add[@class-name='Group']">
		<xsl:variable name="context-name">
			<xsl:call-template name="get-dn-prefix">
				<xsl:with-param name="src-dn" select="@src-dn"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:if test="$context-name = 'CREDICARD1\CRED\GruposIntranet'">
			<!--  if the group is in the right container, then copy the operation  -->
			<xsl:copy>
				<xsl:apply-templates select="node()|@*"/>
			</xsl:copy>
		</xsl:if>
		<!--  if the group is NOT in the right container, discard the operation  -->
	</xsl:template>
	<xsl:template match="rename[@class-name='Group']">
		<xsl:variable name="context-name">
			<xsl:call-template name="get-dn-prefix">
				<xsl:with-param name="src-dn" select="@src-dn"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:if test="$context-name = 'CREDICARD1\CRED\GruposIntranet'">
			<!--  if the group is in the right container, then copy the operation  -->
			<xsl:copy>
				<xsl:apply-templates select="node()|@*"/>
			</xsl:copy>
		</xsl:if>
		<!--  if the group is NOT in the right container, discard the operation  -->
	</xsl:template>
	<xsl:template match="delete[@class-name='Group']">
		<xsl:variable name="context-name">
			<xsl:call-template name="get-dn-prefix">
				<xsl:with-param name="src-dn" select="@src-dn"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:if test="$context-name = 'CREDICARD1\CRED\GruposIntranet'">
			<!--  if the group is in the right container, then copy the operation  -->
			<xsl:copy>
				<xsl:apply-templates select="node()|@*"/>
			</xsl:copy>
		</xsl:if>
		<!--  if the group is NOT in the right container, discard the operation  -->
	</xsl:template>
	<xsl:template match="modify[@class-name='Group']">
		<xsl:variable name="context-name">
			<xsl:call-template name="get-dn-prefix">
				<xsl:with-param name="src-dn" select="@src-dn"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:if test="$context-name = 'CREDICARD1\CRED\GruposIntranet'">
			<!--  if the group is in the right container, then copy the operation  -->
			<xsl:copy>
				<xsl:apply-templates select="node()|@*"/>
			</xsl:copy>
		</xsl:if>
		<!--  if the group is NOT in the right container, discard the operation  -->
	</xsl:template>
	<xsl:template match="move[@class-name='Group']">
		<!--  DISCARD group moves in the Corp Tree  -->
	</xsl:template>
	<xsl:template match="modify[modify-attr[@attr-name='Group Membership']]">
		<!-- When modifying USERS's Group Membership, check if the group is OK before processing -->
		<xsl:variable name="group-being-added" select="string(modify-attr[@attr-name='Group Membership']/add-value/value)"/>
		<xsl:variable name="group-being-removed" select="string(modify-attr[@attr-name='Group Membership']/remove-value/value)"/>
		<xsl:variable name="added-group-context">
			<xsl:call-template name="get-dn-prefix">
				<xsl:with-param name="src-dn" select="$group-being-added"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="removed-group-context">
			<xsl:call-template name="get-dn-prefix">
				<xsl:with-param name="src-dn" select="$group-being-removed"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:if test="$added-group-context = 'CREDICARD1\CRED\GruposIntranet'">
			<!--  if the group is in the right container, then copy the operation  -->
			<!--  if NOT, then DISCARD  -->
			<xsl:copy>
				<xsl:apply-templates select="node()|@*"/>
			</xsl:copy>
		</xsl:if>
		<xsl:if test="$removed-group-context = 'CREDICARD1\CRED\GruposIntranet'">
			<!--  if the group is in the right container, then copy the operation  -->
			<!--  if NOT, then DISCARD  -->
			<xsl:copy>
				<xsl:apply-templates select="node()|@*"/>
			</xsl:copy>
		</xsl:if>
	</xsl:template>
	<xsl:template match="move[@class-name='User']">
		<!--  DISCARD user moves in the Corp Tree  -->
	</xsl:template>
	<!--  this template separates the context of the cn  -->
	<xsl:template name="get-dn-prefix" xmlns:jstring="http://www.novell.com/nxsl/java/java.lang.String">
		<xsl:param name="src-dn"/>
		<!-- use java string stuff to make this much easier -->
		<xsl:variable name="dn" select="jstring:new($src-dn)"/>
		<xsl:variable name="index" select="jstring:lastIndexOf($dn,'\')"/>
		<xsl:if test="$index != -1">
			<!--  toma el substring desde el caracter 1 (quita el "\")  -->
			<!--  hasta que comienza el "\cn"  -->
			<xsl:value-of select="jstring:substring($dn,1,$index)"/>
		</xsl:if>
	</xsl:template>
</xsl:transform>
