<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:util="http://www.pnp-software.com/util" xmlns:ax="http://control.ee.ethz.ch/XWeaver/AspectX" version="2.0">
  
  <xd:doc type="stylesheet">
    
<xd:short>Weaving Rule that weaves a code fragment at the beginning of a block.</xd:short>
    
<xd:detail>
      
<ul>
        
<li>srcML element: <code>src:block</code>
        
</li>
        
<li>advice type: <code>begin</code>
        
</li>
        
<li>codeModifier type: <code>codeFragment</code>
        
</li>
      
</ul>
      
<h2>Example 1</h2>
      
<h3>Base Code</h3>
      
<div class="source">
<pre>int foo() {
  printf("Hello");
}
</pre>
      
</div>
      
<h3>Code Modifier</h3>
      
<xd:xml>
<codeModifier type="codeFragment">
  
<text>printf("Hello World")</text>
</codeModifier>
      
</xd:xml>
      
<h3>Modified Code</h3>
      
<div class="source">
<pre>int foo() {
  
<span class="highlightedCode">printf("Hello World");</span>
  printf("Hello");
}
</pre>
      
</div>
      
<xd:weaverRuleLinks pointcutType="src:block" adviceType="begin" codeModifierType="codeFragment" />
    
</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> Apply tempates with mode <code>weaving_block_begin_codeFragment</code> to all (excludig
    advice elements) 
<code>src:block</code> child elements. </xd:doc>

  
<xsl:template match="src:block[ax:advice[@type='begin' and position() = 1]/ax:codeModifier[@type='codeFragment']]" mode="weaving">
    
<xsl:copy>
      
<xsl:copy-of select="@*" />
      
<!-- The current advice has to be deleted. All others must be preserved.  -->
      
<xsl:copy-of select="ax:advice[position() != 1]" />
      
<xsl:call-template name="addAtBeginOfBlock">
        
<xsl:with-param name="block" select="." />
        
<xsl:with-param name="advice" select="ax:advice[1]" />
      
</xsl:call-template>
    
</xsl:copy>
  
</xsl:template>
</xsl:stylesheet>






































v