<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>Replaces an expression by a code fragment.</xd:short>
    
<xd:detail>
      
<ul> 
        
<li>srcML element:     <code>src:expr</code></li>
        
<li>advice type:       <code>replace</code></li>
        
<li>codeModifier type: <code>codeFragment</code></li>
      
</ul>
      
<xd:weaverRuleLinks pointcutType="src:expr" adviceType="replace" 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>

  
  
                   <xd:doc>
    Replaces a expression with a code fragment.
    If the expression element contains other advices, these must be handled first. This is
    achieved by moving the replace advice to the end of the pending advices.
  
</xd:doc>

  
<xsl:template match="src:expr[ax:advice[@type='replace' and position() = 1]/ax:codeModifier[@type='codeFragment']]" mode="weaving">
    
<!-- ASSERT: If there are other advices of type replace, output error and terminate proram -->
    
<xsl:if test="count(ax:advice[@type='replace']) &gt; 1">
      
<xsl:message terminate="yes">[ERROR] expr_replace_codeFragment.xsl, only one replace advice is allowed per element! 
      
<xsl:value-of select="string-join(ax:advice[@type='replace']/@name,',')" /></xsl:message>
    
</xsl:if>
    
<xsl:choose>
      
<xsl:when test="count(ax:advice) &gt; 1">
        
<!-- Move advice to end of advice list, if there is more than one advice present -->
        
<xsl:copy>
          
<xsl:copy-of select="@*" />
          
<xsl:copy-of select="ax:advice[position() != 1]" />
          
<xsl:copy-of select="ax:advice[1]" />
          
<xsl:apply-templates mode="weaving" />
        
</xsl:copy>
      
</xsl:when>
      
<xsl:otherwise>
        
<!-- There is only one advice so we can process it -->
        
<!-- Find out indentation -->
        
<xsl:variable name="indent" select="util:repeatString($defaultIndentation, count(ancestor::src:block) + 1 - count(parent::src:block))" />
        
        
<!-- Add codeFragment instead of the expr element -->
        
<ax:inserted><xsl:value-of select="util:indentText(xw:getCodeModifierContent(ax:advice[1]/ax:codeModifier), $indent, false())" /></ax:inserted>
      
</xsl:otherwise>
    
</xsl:choose>
  
</xsl:template>
</xsl:stylesheet>






































v