<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lotus="http://www.lotus.com/dxl">
	<xsl:output method="xml" encoding="utf-8" indent="no" cdata-section-elements="lotus:lotusscript"/>
	<xsl:variable name="crlf" select="'&#x0D;&#x0A;'"/>
	
	<!-- Copying attributes with names (in original structure) -->
	<xsl:template match="@*">
		<xsl:copy-of select="."/>
	</xsl:template>

	<xsl:template match="*">
		<xsl:choose>
			<xsl:when test="self::*">
				<!-- Is Element Node (Could be a whitespace) -->
				<xsl:copy>
					<!-- Copying attributes -->
					<xsl:apply-templates select="@*"/>
					<xsl:if test="count(child::*) > 0 and not (ancestor-or-self::lotus:par)">
						<xsl:value-of select="$crlf"/>
					</xsl:if>
					<xsl:choose>
						<!-- Copying contents -->
						<xsl:when test="self::lotus:database">
							<xsl:apply-templates select="child::*">
								<xsl:sort select="name()" />
								<xsl:sort select="@name"/>
							</xsl:apply-templates>
						</xsl:when>
						<xsl:otherwise>
							<xsl:apply-templates select="child::node()" />
						</xsl:otherwise>
					</xsl:choose>
				</xsl:copy>
				<xsl:if test="not (ancestor::lotus:par)">
					<xsl:value-of select="$crlf"/>
				</xsl:if>
			</xsl:when>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="text()">
		<xsl:choose>
			<xsl:when test="normalize-space(.) = ''">
				<xsl:if test="parent::lotus:lotusscript | parent::lotus:formula">
					<xsl:value-of select="$crlf"/>
				</xsl:if>
			</xsl:when>
			<xsl:otherwise>
				<xsl:copy-of select="."/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="/">
		<!-- Needed only to put first document element on new line -->
		<xsl:copy>
			<xsl:apply-templates select="@* | node()"/>
		</xsl:copy>
	</xsl:template>
	
	<!-- exclude specific attributs from the xml -->
	<xsl:template match="lotus:database/@*" />
	<xsl:template match="lotus:actionbar/@showdefaultrightclickitems" />
	<xsl:template match="lotus:*/@designerversion" />
	<xsl:template match="lotus:imageref/@database" />
	<xsl:template match="lotus:*/@propagatenoreplace" />
	<xsl:template match="lotus:*/@noreplace" />
	<xsl:template match="lotus:pardef/@tabs" />
	<xsl:template match="lotus:javaproject/@codepath" />
	
	<!-- exclude specific elements from the xml -->
	<xsl:template match="lotus:compositedata" />	
	<xsl:template match="lotus:databaseinfo" />	
	<xsl:template match="lotus:launchsettings" />	
	<xsl:template match="lotus:form/lotus:item[@name != '$AUTOLAUNCH']" />	
	<xsl:template match="lotus:subform/lotus:item" />
	<xsl:template match="lotus:view/lotus:item" />
	<xsl:template match="lotus:view/@formatnoteid" />
	<xsl:template match="lotus:folder/@formatnoteid" />
	<xsl:template match="lotus:noteinfo" />
	<xsl:template match="lotus:updatedby" />
	<xsl:template match="lotus:wassignedby" />
	<xsl:template match="lotus:agent/lotus:designchange" />
	<xsl:template match="lotus:agent/lotus:rundata" />
	<xsl:template match="lotus:fulltextsettings" />	
	<xsl:template match="lotus:revisions" />
</xsl:stylesheet>