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: Re: [docbook-apps] C++ const and virtual methods


Hi Simon,
I can help with the position template:

<xsl:template name="elementpos">
   <xsl:param name="ename"/>

  <xsl:value-of
        select="count(*[local-name() = $ename][1]/preceding-sibling::*)+1"/>

</xsl:template>

The * selects all the child elements, the first predicate narrows them down
to
those whose local-name matches the parameter value, the second predicate
narrows the list down to the first one of those (in case there is more than
one), and the
next step after the / finds all the elements that precede it.  Then you
count
those and add 1 to get the position of the element in question.

You should add a test to make sure there exists an element matching $ename,
though.

Let me know if this doesn't work.

Bob Stayton
Sagehill Enterprises
DocBook Consulting
bobs@sagehill.net


----- Original Message ----- 
From: "Simon Kennedy" <stonewolfsoft@yahoo.co.uk>
To: "DocBook Apps Mailing List" <docbook-apps@lists.oasis-open.org>
Sent: Monday, August 08, 2005 5:24 AM
Subject: [docbook-apps] 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: docbook-apps-unsubscribe@lists.oasis-open.org
> For additional commands, e-mail: docbook-apps-help@lists.oasis-open.org
>
>
>




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