<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output omit-xml-declaration="yes" method="xml" media-type="text/xml" indent="yes" encoding="utf-8"/>

<xsl:template name='copy'>
	
	<xsl:variable name="mode">
		<xsl:choose>
			<xsl:when test="//article">1</xsl:when>
			<xsl:when test="//main">2</xsl:when>
			<xsl:otherwise>3</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<xsl:choose>
		<xsl:when test="$mode != '2' and ancestor::article | ancestor::div[@property='articleBody'] | ancestor::div[@id='content']">
			<xsl:copy>
				<xsl:apply-templates select="node()|@*"/>
				
				<xsl:if test="not(*) and not(text())">
					<xsl:text> </xsl:text>
				</xsl:if>
			</xsl:copy>
		</xsl:when>
		<xsl:when test="$mode = '2' and ancestor::main">
			<xsl:copy>
				<xsl:apply-templates select="node()|@*"/>
				
				<xsl:if test="not(*) and not(text())">
					<xsl:text> </xsl:text>
				</xsl:if>
			</xsl:copy>
		</xsl:when>
		<xsl:otherwise>
			<xsl:apply-templates select="node()"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>


<xsl:template match="node()|@*">
	<xsl:call-template name='copy'/>
</xsl:template>

<xsl:template match="script"/>
<xsl:template match="style"/>

</xsl:stylesheet>