OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: C++ const and virtual methods


I asked a question about a week ago concerning C++ const and virtual 
methods where the existing stylesheets put all modifiers before the 
method name.

As I received no response I decided to go ahead and start to learn xsl 
to fix the problem. And the result is shown below.

Is there a nicer way than that in the elementpos template below of 
finding the position of an element within it's parent?

<!-- Find the position of the specified element. -->
<xsl:template name="elementpos">
  <xsl:param name="ename"/>

  <xsl:choose>
    <xsl:when test="name(child::*[1]) = $ename">1</xsl:when>
    <xsl:when test="name(child::*[2]) = $ename">2</xsl:when>
    <xsl:when test="name(child::*[3]) = $ename">3</xsl:when>
    <xsl:when test="name(child::*[4]) = $ename">4</xsl:when>
    <xsl:when test="name(child::*[5]) = $ename">5</xsl:when>
    <xsl:when test="name(child::*[6]) = $ename">6</xsl:when>
    <xsl:when test="name(child::*[7]) = $ename">7</xsl:when>
    <xsl:when test="name(child::*[8]) = $ename">8</xsl:when>
    <xsl:when test="name(child::*[9]) = $ename">9</xsl:when>
    <xsl:when test="name(child::*[10]) = $ename">10</xsl:when>
    <xsl:otherwise>9999</xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- Create copy of modifier template with new mode to insert a space 
before the modifier not after as in original -->
<xsl:template match="modifier" mode="cpp-spacebefore">
  <span class="{name(.)}">
    <xsl:text>&#160;</xsl:text>
    <xsl:apply-templates mode="cpp"/>
  </span>
</xsl:template>

<!-- Change synopsis to place modifiers which appear after the 
methodname at the end
     This is to handle const methods and virtual methods i.e. '= 0' in c++.
-->
<xsl:template mode="cpp" 
match="constructorsynopsis|destructorsynopsis|methodsynopsis">
  <xsl:variable name="pos">
    <xsl:call-template name="elementpos">
      <xsl:with-param name="ename" select="'methodname'"/>
    </xsl:call-template>
  </xsl:variable>

  <xsl:variable name="modifiers" select="child::*[name(.) = 'modifier' 
and position() &lt; $pos]"/>
  <xsl:variable name="postmodifiers" select="child::*[name(.) = 
'modifier' and position() &gt; $pos]"/>

  <xsl:variable name="notmod" select="*[name(.) != 'modifier']"/>
  <xsl:variable name="decl">
    <xsl:if test="parent::classsynopsis">
      <xsl:text>&#160;&#160;</xsl:text>
    </xsl:if>
    <xsl:apply-templates select="$modifiers" mode="cpp"/>

    <!-- type -->
    <xsl:if test="name($notmod[1]) != 'methodname'">
      <xsl:apply-templates select="$notmod[1]" mode="cpp"/>
    </xsl:if>

    <xsl:apply-templates select="methodname" mode="cpp"/>
  </xsl:variable>

  <code class="{name(.)}">
    <xsl:copy-of select="$decl"/>
    <xsl:text>(</xsl:text>
    <xsl:apply-templates select="methodparam" mode="cpp">
      <xsl:with-param name="indent" select="string-length($decl)"/>
    </xsl:apply-templates>
    <xsl:text>)</xsl:text>

    <xsl:apply-templates select="$postmodifiers" mode="cpp-spacebefore"/>

    <xsl:if test="exceptionname">
      <br/>
      <xsl:text>&#160;&#160;&#160;&#160;throws&#160;</xsl:text>
      <xsl:apply-templates select="exceptionname" mode="cpp"/>
    </xsl:if>
    <xsl:text>;</xsl:text>
  </code>
  <xsl:call-template name="synop-break"/>
</xsl:template>

Regards
Simon Kennedy

		
___________________________________________________________ 
How much free photo storage do you get? Store your holiday 
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]