<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="xml" encoding="UTF-8" indent="yes" />
	<xsl:template match="* | @* | node()">
		<xsl:copy>
			<xsl:apply-templates select="* | @* | node()" />
		</xsl:copy>
	</xsl:template>

	<xsl:template match="C319[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C319 Type="6" Activator="ScrollUp" />
	</xsl:template>
	<xsl:template match="C320[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C320 Type="6" Activator="ScrollDown" />
	</xsl:template>
	<xsl:template match="C302[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C302 Type="5" KeySeq="F1"  />
	</xsl:template>
	<xsl:template match="C203[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C203 Type="5" KeySeq="F2"  />
	</xsl:template>
	<xsl:template match="C204[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C204 Type="5" KeySeq="F3"  />
	</xsl:template>
	<xsl:template match="C307[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C307 Type="5" KeySeq="F4"  />
	</xsl:template>
	<xsl:template match="C308[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C308 Type="5" KeySeq="F5"  />
	</xsl:template>
	<xsl:template match="C309[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C309 Type="5" KeySeq="F6"  />
	</xsl:template>
	<xsl:template match="C900[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C900 Type="5" KeySeq="F7"  />
	</xsl:template>
	<xsl:template match="C901[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C901 Type="5" KeySeq="F8"  />
	</xsl:template>
	<xsl:template match="C902[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C902 Type="5" KeySeq="F9"  />
	</xsl:template>
	<xsl:template match="C401[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C401 Type="5" KeySeq="F10" />
	</xsl:template>
	<xsl:template match="C311[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C311 Type="5" KeySeq="F11" />
	</xsl:template>
	<xsl:template match="C310[not(parent::node()[@UniqueName='StandardSupport']) or not(ancestor::ALL)]">
		<C310 Type="5" KeySeq="F12" />
	</xsl:template>

	<xsl:template match="C302|C203|C204|C307|C308|C309|C900|C901|C902|C401|C311|C310">
		<xsl:choose>
			<xsl:when test="parent::node()[@UniqueName='StandardSupport'] and ancestor::ALL"></xsl:when>
			<xsl:otherwise>
				<xsl:copy><!-- just keep what's there already-->
					<xsl:apply-templates select="* | @* | node()" />
				</xsl:copy>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="Application[@UniqueName='StandardSupport' and not(ancestor::ALL)]">
		<Application UniqueName="StandardSupport">
			<C302 Type="5" KeySeq="F1"  />
			<C203 Type="5" KeySeq="F2"  />
			<C204 Type="5" KeySeq="F3"  />
			<C307 Type="5" KeySeq="F4"  />
			<C308 Type="5" KeySeq="F5"  />
			<C309 Type="5" KeySeq="F6"  />
			<C900 Type="5" KeySeq="F7"  />
			<C901 Type="5" KeySeq="F8"  />
			<C902 Type="5" KeySeq="F9"  />
			<C401 Type="5" KeySeq="F10" />
			<C311 Type="5" KeySeq="F11" />
			<C310 Type="5" KeySeq="F12" />
			<!-- also keep what's there already-->
			<xsl:apply-templates select="./*[not(name()='C302' or name()='C203' or name()='C204' or name()='C307' or name()='C308' or name()='C309' or name()='C900' or name()='C901' or name()='C902' or name()='C401' or name()='C311' or name()='C310')]" />
 		</Application>
	</xsl:template>

</xsl:stylesheet>
<!-- 
CREDIT: http://oliiscool.blogspot.com/2006/11/hacking-microsoft-natural-ergonomic.html
POWERSHELL SCRIPT to apply it

function Convert-WithXslt($in,$xsl,$out) 
{
   ## Simplistic error handling
   $xsl = resolve-path $xsl
   if( -not (test-path $xsl) ) { throw "Can't find the XSL file" } 
   $in = resolve-path $in
   if( -not (test-path $in) ) { throw "Can't find the XML file" } 
   $out = resolve-path $out
   if( -not (test-path (split-path $in)) ) { throw "Can't find the output folder" } 

   ## Get an XSL Transform object (try for the new .Net 3.5 version first)
   $EAP = $ErrorActionPreference
   $ErrorActionPreference = "SilentlyContinue"
   $script:xslt = new-object system.xml.xsl.xslcompiledtransfrm
   trap [System.Management.Automation.PSArgumentException] 
   {  # no 3.5, use the slower 2.0 one
      $ErrorActionPreference = $EAP
      $script:xslt = new-object system.xml.xsl.xsltransform
   }
   $ErrorActionPreference = $EAP
   
   ## load xslt file
   $script:xslt.load( $xsl )
     
   ## transform 
   $xslt.Transform( $in, $out )
}

if(-not (test-path "$($env:ProgramFiles)\Microsoft IntelliType Pro\commands.xml")) { throw "You don't seem to have IntelliType installed in the usual directory: '$($env:ProgramFiles)\Microsoft IntelliType Pro'" }
## backup
if(-not (test-path "$($env:ProgramFiles)\Microsoft IntelliType Pro\commands.xml.old")) { copy "$($env:ProgramFiles)\Microsoft IntelliType Pro\commands.xml" "$($env:ProgramFiles)\Microsoft IntelliType Pro\commands.xml.old" }
## Convert
Convert-WithXslt "$($env:ProgramFiles)\Microsoft IntelliType Pro\commands.xml.old" IntelliTypeFix.xsl "$($env:ProgramFiles)\Microsoft IntelliType Pro\commands.xml"
kill -name itype; &"$($env:ProgramFiles)\Microsoft IntelliType Pro\itype.exe"
-->
