<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">
<xsl:output method="xml" version="1.0" encoding="UTF-8" omit-xml-declaration="yes" indent="yes"/>
 
	<!-- this will match and every node & attribute copy to output as it parses -->
	<xsl:template match="@* | node()">
		<xsl:copy>
			<xsl:apply-templates select="@* | node()"/>
		</xsl:copy>
	</xsl:template>
	
	<!-- this will match the program node & attribute copy to output when matched against the program node -->
	<xsl:template match="program">
	
				<xsl:copy>
					<!-- this will cause table_field/Tablebold/table_field[@title='Study_Method'] | table_field nodes to be copied under as child nodes of program element, but wont copy the child elements i.e. the incorrectly nested table_field[@title='Study_Method'], this is added explicitly to the other table_filed nodes on the same level -->
					<xsl:apply-templates select="Tableheading | table_field/Tablebold/table_field[@title='Study_Method']" mode="element-node-mod" />
					
					<!--<xsl:apply-templates select="table_field[@title='Qualification']" mode="element-node-mod" />-->
					<xsl:apply-templates select="table_field[@title='Qualification'] | table_field[@*[name() != 'Study_Method' and name() != 'Qualification']]" mode="element-node-mod" />
					
					<!-- this will cause nodes to be suppressed -->
					<xsl:apply-templates select="ParagraphSection" mode="element-node-mod"/>
					
				</xsl:copy>
	
	</xsl:template>
	<!-- Do not copy table_field/Tablebold/table_field[@title='Study_Method'] | table_field nodes to the output document i.e. doesn't out put the source xml nodes matching tablefields -->
	<xsl:template match="Tableheading | table_field[@title='Qualification'] | table_field/Tablebold/table_field[@title='Study_Method'] | table_field[@*[name() != 'Study_Method' and name() != 'Qualification']] | ParagraphSection" />
	
	<!-- We can optionally Modify (add nodes etc here) and explicitly output the above copied table_fields and their child nodes, note the rouge  table_field[@title='Study_Method'] was broken out in the above template call,  table_field/Tablebold/table_field[@title='Study_Method'] | table_field nodes and copy to the output document -->

	<xsl:template match="Tableheading | table_field[@title='Qualification'] | table_field/Tablebold/table_field[@title='Study_Method'] | table_field[@*[name() != 'Study_Method' and name() != 'Qualification']] | ParagraphSection" mode="element-node-mod">
		<xsl:copy>
			<!--<xsl:copy-of select="@*" />-->
			<!--<xsl:apply-templates select="@*[not(name()='Study_Method')] | node()"/>-->
			<xsl:apply-templates select="@* | node()"/>
		</xsl:copy>
	</xsl:template>

</xsl:stylesheet>
