<?xml version="1.0" encoding="UTF-8"?>
<!-- XSLT Filter um Weichen aus iTrain in Calc zu importieren -->
<!-- Status: ok -->
<!-- Hinweise und Fehler an tuxator@tuxator.de -->
<!-- ############################################################################################### -->
<!--              Struktur des Weichen-Knotens der iTrain-XML-Datei                               -->
<!-- ############################################################################################### -->
<!--   <turnout name="HB Weiche 1" type="left" state="straight"> -->
<!--    <description>Ausfahrt Abzweig</description> -->
<!--    <interface name="TAMS MC" address="1"/> -->
<!--    <options> -->
<!--      <option>reset</option> -->
<!--    </options> -->
<!--    <length unit="cm" count="2"> -->
<!--      <state-length state="straight">18.5</state-length> -->
<!--      <state-length state="branch">19.5</state-length> -->
<!--    </length> -->
<!--   </turnout> -->
<!-- ############################################################################################### -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:tra="http://www.berros.eu/xml/train" exclude-result-prefixes="tra">
	<xsl:decimal-format name="westeuropa" decimal-separator=',' grouping-separator='.' />
    <xsl:template match="/">
		<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" office:version="1.0">
		<office:automatic-styles>
			<!-- Formate für Spalten -->
			<!-- Art -->
			<style:style style:name="co1" style:family="table-column">
				<style:table-column-properties fo:break-before="auto" style:column-width="18.0mm"/>
			</style:style>
			<!-- Typ -->
			<style:style style:name="co2" style:family="table-column">
				<style:table-column-properties fo:break-before="auto" style:column-width="18.0mm"/>
			</style:style>
			<!-- Name -->
			<style:style style:name="co3" style:family="table-column">
				<style:table-column-properties fo:break-before="auto" style:column-width="54.0mm"/>
			</style:style>
			<!-- Beschreibung -->
			<style:style style:name="co4" style:family="table-column">
				<style:table-column-properties fo:break-before="auto" style:column-width="108.0mm"/>
			</style:style>
			<!-- Adresse -->
			<style:style style:name="co5" style:family="table-column">
				<style:table-column-properties fo:break-before="auto" style:column-width="18.0mm"/>
			</style:style>
			<!-- Adresse 2 -->
			<style:style style:name="co6" style:family="table-column">
				<style:table-column-properties fo:break-before="auto" style:column-width="18.0mm"/>
			</style:style>
			<!-- Länge -->
			<style:style style:name="co7" style:family="table-column">
				<style:table-column-properties fo:break-before="auto" style:column-width="21.5mm"/>
			</style:style>
			<!-- Länge 2 -->
			<style:style style:name="co8" style:family="table-column">
				<style:table-column-properties fo:break-before="auto" style:column-width="21.5mm"/>
			</style:style>
			<!-- Länge 3 -->
			<style:style style:name="co9" style:family="table-column">
				<style:table-column-properties fo:break-before="auto" style:column-width="21.5mm"/>
			</style:style>
			<!-- Länge 4 -->
			<style:style style:name="co10" style:family="table-column">
				<style:table-column-properties fo:break-before="auto" style:column-width="21.5mm"/>
			</style:style>
			<!-- Kommentar -->
			<style:style style:name="co11" style:family="table-column">
				<style:table-column-properties fo:break-before="auto" style:column-width="90.0mm"/>
			</style:style>
			<!-- Formate für Zellen -->
			<!-- ce1 linksbündig, 1pt Umrandung -->
			<style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default">
				<style:table-cell-properties fo:border="1pt solid #000000" style:text-align-source="fix" style:repeat-content="false"/>
				<style:paragraph-properties fo:text-align="start"/>
			</style:style>
			<!-- ce2 rechtsbündig, 1pt Umrandung -->
			<style:style style:name="ce2" style:family="table-cell" style:parent-style-name="Default">
				<style:table-cell-properties fo:border="1pt solid #000000" style:text-align-source="fix" style:repeat-content="false"/>
				<style:paragraph-properties fo:text-align="end"/>
			</style:style>
			<!-- ce3 mittig, Fett, 1pt Umrandung,  Hintergrundfarbe -->
			<style:style style:name="ce3" style:family="table-cell" style:parent-style-name="Default">
				<style:table-cell-properties fo:border="1pt solid #000000" fo:background-color="#009185" style:vertical-align="middle"/>
				<style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/>
				<style:paragraph-properties fo:text-align="center"/>
			</style:style>
		</office:automatic-styles>
		<!-- Aufbau Tabelle -->
		<office:body>
			<office:spreadsheet>
				<table:table>
				<!-- 11 Spalten für Weichen formatieren -->
				<table:table-column table:style-name="co1" table:default-cell-style-name="Default"/> <!-- Art -->
				<table:table-column table:style-name="co2" table:default-cell-style-name="Default"/> <!-- Typ -->
				<table:table-column table:style-name="co3" table:default-cell-style-name="Default"/> <!-- Name -->
				<table:table-column table:style-name="co4" table:default-cell-style-name="Default"/> <!-- Beschreibung -->
				<table:table-column table:style-name="co5" table:default-cell-style-name="Default"/> <!-- Adresse -->
				<table:table-column table:style-name="co6" table:default-cell-style-name="Default"/> <!-- Adresse 2 -->
				<table:table-column table:style-name="co7" table:default-cell-style-name="Default"/> <!-- Länge -->
				<table:table-column table:style-name="co8" table:default-cell-style-name="Default"/> <!-- Länge 2 -->
				<table:table-column table:style-name="co9" table:default-cell-style-name="Default"/> <!-- Länge 3 -->
				<table:table-column table:style-name="co10" table:default-cell-style-name="Default"/> <!-- Länge 4 -->
				<table:table-column table:style-name="co11" table:default-cell-style-name="Default"/> <!-- Kommentar -->
				<!-- Überschriften -->
				<!-- 1.Zeile -->
				<table:table-row>
					<table:table-cell table:style-name="ce3" table:number-rows-spanned="3"><text:p>Art</text:p></table:table-cell>
					<table:table-cell table:style-name="ce3" table:number-rows-spanned="3"><text:p>Typ</text:p></table:table-cell>
					<table:table-cell table:style-name="ce3" table:number-rows-spanned="3"><text:p>Name</text:p></table:table-cell>
					<table:table-cell table:style-name="ce3" table:number-rows-spanned="3"><text:p>Beschreibung</text:p></table:table-cell>
					<table:table-cell table:style-name="ce3" table:number-rows-spanned="3"><text:p>Adresse</text:p></table:table-cell>
					<table:table-cell table:style-name="ce3" table:number-rows-spanned="3"><text:p>Adresse 2</text:p></table:table-cell>
					<table:table-cell table:style-name="ce3" table:number-columns-spanned="4" table:number-rows-spanned="2"><text:p>Länge in cm</text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3" table:number-rows-spanned="3"><text:p>Kommentar</text:p></table:table-cell>
				</table:table-row>
				<!-- 2.Zeile -->
				<table:table-row>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
				</table:table-row>
				<!-- 3.Zeile -->
				<table:table-row>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p>Gerade A/C</text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p>Rund B/D</text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p>B/C</text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p>A/D</text:p></table:table-cell>
					<table:table-cell table:style-name="ce3"><text:p></text:p></table:table-cell>
				</table:table-row>
				<!-- alle Weichen -->
				<xsl:for-each select="/tra:train-control/tra:control-items/tra:accessories/tra:turnout">
					<table:table-row>
						<!-- Art -->
						<table:table-cell table:style-name="ce1">
							<text:p>Weiche</text:p>
						</table:table-cell>
						<!-- Typ -->
						<table:table-cell table:style-name="ce1">
							<xsl:if test="./@type = 'cross-fixed'">
								<text:p>Kreuzung</text:p>
							</xsl:if>
							<xsl:if test="./@type = 'left'">
								<text:p>Links</text:p>
							</xsl:if>
							<xsl:if test="./@type = 'right'">
								<text:p>Rechts</text:p>
							</xsl:if>
							<xsl:if test="./@type = 'cross-double-slip'">
								<text:p>DKW</text:p>
							</xsl:if>
						</table:table-cell>
						<!-- Name -->
						<table:table-cell table:style-name="ce1"><text:p><xsl:value-of select="./@name"/></text:p></table:table-cell>
						<!-- Beschreibung -->
						<table:table-cell table:style-name="ce1"><text:p><xsl:value-of select="tra:description"/></text:p></table:table-cell>
						<!-- Adresse -->
						<xsl:choose>
							<xsl:when test="tra:interface/@address">
								<table:table-cell table:style-name="ce2"><text:p><xsl:value-of select="tra:interface/@address"/></text:p></table:table-cell>
								<table:table-cell table:style-name="ce2"></table:table-cell>
							</xsl:when>
							<xsl:otherwise>
								<xsl:for-each select="./tra:interface">
									<table:table-cell table:style-name="ce2"><text:p><xsl:value-of select="./tra:address[1]"/></text:p></table:table-cell>
									<!-- Adresse 2 -->
									<table:table-cell table:style-name="ce2"><text:p><xsl:value-of select="./tra:address[2]"/></text:p></table:table-cell>
								</xsl:for-each>
							</xsl:otherwise>
						</xsl:choose>
						<!-- Länge -->
						<xsl:choose>
							<xsl:when test="tra:length/@count">
								<xsl:for-each select="./tra:length">
									<!-- Gerade A/C -->
									<table:table-cell table:style-name="ce2"><text:p><xsl:value-of select="format-number(./tra:state-length[1], '##00.0##', 'westeuropa')"/></text:p></table:table-cell>
									<!-- Rund B/D -->
									<table:table-cell table:style-name="ce2"><text:p><xsl:value-of select="format-number(./tra:state-length[2], '##00.0##', 'westeuropa')"/></text:p></table:table-cell>
									<!-- B/C -->
									<table:table-cell table:style-name="ce2">
									<xsl:if test="./tra:state-length[3]">
										<text:p><xsl:value-of select="format-number(./tra:state-length[3], '##00.0##', 'westeuropa')"/></text:p>
									</xsl:if>
									</table:table-cell>
									<!-- A/D -->
									<table:table-cell table:style-name="ce2">
									<xsl:if test="./tra:state-length[4]">
										<text:p><xsl:value-of select="format-number(./tra:state-length[4], '##00.0##', 'westeuropa')"/></text:p>
									</xsl:if>
									</table:table-cell>
								</xsl:for-each>
							</xsl:when>
							<xsl:otherwise>
								<xsl:choose>
								<xsl:when test="tra:length">
									<table:table-cell table:style-name="ce2"><text:p><xsl:value-of select="format-number(./tra:length, '##00.0##', 'westeuropa')"/></text:p></table:table-cell>
									<table:table-cell table:style-name="ce2"><text:p><xsl:value-of select="format-number(./tra:length, '##00.0##', 'westeuropa')"/></text:p></table:table-cell>
									<table:table-cell table:style-name="ce2"></table:table-cell>
									<table:table-cell table:style-name="ce2"></table:table-cell>
								</xsl:when>
								<xsl:otherwise>
									<table:table-cell table:style-name="ce2"></table:table-cell>
									<table:table-cell table:style-name="ce2"></table:table-cell>
									<table:table-cell table:style-name="ce2"></table:table-cell>
									<table:table-cell table:style-name="ce2"></table:table-cell>
								</xsl:otherwise>
								</xsl:choose>
							</xsl:otherwise>
						</xsl:choose>
						<!-- Kommentar -->
						<table:table-cell table:style-name="ce1"><text:p><xsl:value-of select="tra:comment"/></text:p></table:table-cell>
					</table:table-row>
				</xsl:for-each>
				</table:table>
			</office:spreadsheet>
		</office:body>
		</office:document-content>
	</xsl:template>
</xsl:stylesheet>
