User:RailML Coord Documentation/code.xsl: Difference between revisions

From railML 2 Wiki
Jump to navigation Jump to search
m (Ferri Leberl moved page Code.xsl to User:Ferri Leberl/code.xsl)
(Replaced content with "{{mirror|{{iuser}}}}")
Tag: Replaced
Line 1: Line 1:
<syntaxhighlight lang=xml>
{{mirror|{{iuser}}}}
<?xml version = "1.0" encoding = "UTF-8"?>
  <xsl:stylesheet version = "2.0"
      xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:for-each select="//element()">
        <xsl:value-of select="name()"/>
        <xsl:text>&#x9;&#x9;</xsl:text><!-- Lücke für Kommentar-->
<!-- Subschema -->
      <xsl:choose>
<xsl:when test="ancestor::*:infrastructure">
        <xsl:text>IS</xsl:text>
</xsl:when>
<xsl:when test="ancestor::*:infrastructureVisualizations">
        <xsl:text>IS</xsl:text>
</xsl:when>
<xsl:when test="ancestor::*:rollingstock">
        <xsl:text>RS</xsl:text>
</xsl:when>
<xsl:when test="ancestor::*:timetable">
        <xsl:text>TT</xsl:text>
</xsl:when>
<xsl:when test="ancestor::*:interlocking">
        <xsl:text>IL</xsl:text>
</xsl:when>
<xsl:when test="self::*:infrastructure">
        <xsl:text>IS</xsl:text>
</xsl:when>
<xsl:when test="self::*:infrastructureVisualizations">
        <xsl:text>IS</xsl:text>
</xsl:when>
<xsl:when test="self::*:rollingstock">
        <xsl:text>RS</xsl:text>
</xsl:when>
<xsl:when test="self::*:timetable">
        <xsl:text>TT</xsl:text>
</xsl:when>
<xsl:when test="self::*:interlocking">
        <xsl:text>IL</xsl:text>
</xsl:when>
<xsl:otherwise>
        <xsl:text>CO</xsl:text>
</xsl:otherwise>
</xsl:choose>
        <xsl:text>&#x9;</xsl:text>
<!-- /Subschema -->
        <xsl:value-of select="name(..)"/><!--parent-->
<xsl:text>&#x9;</xsl:text>
        <!-- Direct children:
        The `*` here in the `select` statement just selects
        all child elements.  This could also be expressed
        (perhaps more clearly, but also more verbosely) as
        either of the following:
            ./*
            child::*
        -->
        <xsl:for-each select="*">
            <!-- We put the semicolon before each child's name.
                That way, if there are no children, we don't have
                an extraneous semicolon after the parent's name.-->
            <xsl:text>;</xsl:text>
            <xsl:value-of select="name()"/>
        </xsl:for-each>
        <xsl:text>&#x9;</xsl:text>
<!-- Attribute -->
        <xsl:for-each select="@*">
            <xsl:text>;</xsl:text>
            <xsl:value-of select="name()"/>
        </xsl:for-each>
        <xsl:text>&#x9;&#x9;&#x9;</xsl:text><!-- Lücke für Attributkommentare, Pflichtelement und Pflichtattribute -->
<!-- /Attribute -->
        <xsl:text>&#10;</xsl:text>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</syntaxhighlight>

Revision as of 12:55, 19 June 2020