<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="scene">
		<scene>
			<xsl:attribute name="id"><xsl:value-of select="ancestor::act/@id"></xsl:value-of>_<xsl:value-of select="count(preceding-sibling::scene)+1"></xsl:value-of></xsl:attribute>
			<xsl:apply-templates/>
		</scene>
	</xsl:template>

	<xsl:template match="speech">
		<speech>
			<xsl:attribute name="id"><xsl:value-of select="ancestor::act/@id"></xsl:value-of>_<xsl:value-of select="count(ancestor::scene/preceding-sibling::scene)+1"></xsl:value-of>_<xsl:value-of select="count(preceding-sibling::speech)+1"></xsl:value-of></xsl:attribute>
			<xsl:apply-templates/>
		</speech>
	</xsl:template>
	
	
	<xsl:template match="line">
		<line>
			<xsl:attribute name="id"><xsl:value-of select="ancestor::act/@id"></xsl:value-of>_<xsl:value-of select="count(ancestor::scene/preceding-sibling::scene)+1"></xsl:value-of>_<xsl:value-of select="count(ancestor::speech//preceding-sibling::speech)+1"></xsl:value-of>_<xsl:value-of select="count(preceding-sibling::line)"></xsl:value-of></xsl:attribute>
			<xsl:apply-templates/>
		</line>
	</xsl:template>

	
	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>
