<xsl:stylesheet xmlns:src="http://www.sdml.info/srcML/src" xmlns:cpp="http://www.sdml.info/srcML/cpp" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xw="http://www.pnp-software.com/XWeaver" xmlns:xd="http://www.pnp-software.com/XSLTdoc" xmlns:ax="http://control.ee.ethz.ch/XWeaver/AspectX" version="2.0">
                
  
                   <xd:doc type="stylesheet">
    
<xd:short>Weaving Rule that adds a definition to a unit.</xd:short>
    
<xd:detail>
      
<ul> 
        
<li>srcML element:     <code>src:unit</code></li>
        
<li>advice type:       <code>add</code></li>
        
<li>codeModifier type: <code>definition</code></li>
      
</ul>
      
<p>The definition is always added at the end of the unit.</p>
      
<h2>Example</h2>
      
<div class="source">
<pre>#include &lt;stdio.h&gt;
void Foo:foo() {
  printf("foo");
}
</pre>
      
</div>
      
<h3>Code Modifier</h3>
      
<xd:xml>
<codeModifier type="definition">
  
<text>void Foo:foo1() {</text>
  
<text>  printf("foo1");</text>
  
<text>}</text>
</codeModifier>
      
</xd:xml>
      
<h3>Modified Code</h3>
      
<div class="source">
<pre>#include &lt;stdio.h&gt;
void Foo:foo() {
  printf("foo");
}
<span class="highlightedCode">void Foo:foo1() {
  printf("foo1");
}
</span></pre>
      
</div>
     
<xd:weaverRuleLinks pointcutType="src:unit" adviceType="add" codeModifierType="definition" />
    
</xd:detail>
    
<xd:cvsId>$Id$</xd:cvsId>
    
<xd:author>ibirrer</xd:author>
    
<xd:copyright>2004, P&amp;P Software GmbH</xd:copyright>
  
</xd:doc>

  
  
<!-- Preserve Whitespaces -->
  
<xsl:preserve-space elements="*" />
  
  
                   <xd:doc>
    Adds a definition to a unit.
  
</xd:doc>

  
<xsl:template match="src:unit[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='definition']]" mode="weaving">
    
<xsl:copy>
      
<xsl:copy-of select="@*" />
      
<!-- The current advice is deleted. Others are preserved.  -->
      
<xsl:copy-of select="ax:advice[position() != 1]" />
      
      
<!-- Weave everything else -->
      
<xsl:apply-templates select="child::node()[not(self::ax:advice)]" mode="weaving" />
      
      
<!-- add the methodDefinition -->
      
<!-- Add newline -->
      
<xsl:text>
</xsl:text>
      
<xsl:value-of select="xw:getCodeModifierContent(ax:advice[1]/ax:codeModifier)" />
    
</xsl:copy>
  
</xsl:template>
</xsl:stylesheet>






































v