Source

amqpev / amqpev / spec / filter_method_decls.xsl

Full commit
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  xmlns:str="http://xsltsl.org/string">

<xsl:import href="string.xsl" />

<xsl:template name="pythonize-name-spaces">
  <xsl:param name="name" />
  <xsl:call-template name="str:subst">
    <xsl:with-param name="text" select="$name" />
    <xsl:with-param name="replace" xml:space="preserve"> </xsl:with-param>
    <xsl:with-param name="with">_</xsl:with-param>
  </xsl:call-template>
</xsl:template>

<xsl:template name="pythonize-name-hyphens">
  <xsl:param name="name" />
  <xsl:call-template name="str:subst">
    <xsl:with-param name="text" select="$name" />
    <xsl:with-param name="replace">-</xsl:with-param>
    <xsl:with-param name="with">_</xsl:with-param>
  </xsl:call-template>
</xsl:template>

<xsl:template name="pythonize-name">
  <xsl:param name="name" />
  <xsl:call-template name="pythonize-name-spaces">
    <xsl:with-param name="name">
      <xsl:call-template name="pythonize-name-hyphens">
        <xsl:with-param name="name" select="$name" />
      </xsl:call-template>
    </xsl:with-param>
  </xsl:call-template>
</xsl:template>

<xsl:template match="amqp">
  <amqp>
    <packing type="octet" code="B" />
    <packing type="short" code="H" />
    <packing type="long" code="L" />
    <packing type="longlong" code="Q" />
    <packing type="timestamp" code="Q" pack="pack_ts" unpack="unpack_ts" />
    <packing type="table" code="L:" pack="pack_table" unpack="unpack_table" />
    <packing type="longstr" code="L:" pack="pack_str" unpack="unpack_str" />
    <packing type="shortstr" code="B:" pack="pack_str" unpack="unpack_str" />
    <packing type="bit" code="." />

    <xsl:apply-templates select="class" />

  </amqp>
</xsl:template>

<xsl:template match="class">
  <class name="{@name}" id="{@index}">
    <xsl:apply-templates select="method|field" />
  </class>
</xsl:template>

<xsl:template match="method">
  <method id="{@index}">
    <xsl:attribute name="name">
      <xsl:call-template name="pythonize-name-hyphens">
        <xsl:with-param name="name" select="@name" />
      </xsl:call-template>
    </xsl:attribute>

    <xsl:apply-templates select="field" />

  </method>
</xsl:template>

<xsl:template match="field">
  <field>
    <xsl:attribute name="name">
      <xsl:call-template name="pythonize-name">
        <xsl:with-param name="name" select="@name" />
      </xsl:call-template>
    </xsl:attribute>

    <xsl:choose>
      <xsl:when test="@type">
        <xsl:attribute name="type">
          <xsl:value-of select="@type" />
        </xsl:attribute>
      </xsl:when>

      <xsl:when test="@domain">
        <xsl:variable name="domain" select="@domain" />
        <xsl:attribute name="type">
          <xsl:value-of select="//domain[@name=$domain]/@type" />
        </xsl:attribute> 
      </xsl:when>

    </xsl:choose>

  </field>
</xsl:template>

<xsl:template match="*">
  <!-- Don't emit any elements except those explicitly matched -->
</xsl:template>

</xsl:stylesheet>