<
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 a comment elmement by a code fragment.</
xd:
short>
<
xd:
detail>
<
ul>
<
li>
srcML element: <
code>
src:comment</
code></
li>
<
li>
advice type: <
code>
replace</
code></
li>
<
li>
codeModifier type: <
code>
codeFragment</
code></
li>
</
ul>
<
h2>
Example</
h2>
<
h3>
Base Code</
h3>
<
div class="
source">
<
pre>
int foo( int i )
/** Assert 0 */
return 200;
}</
pre>
</
div>
<
h3>
Code Modifier</
h3>
<
xd:
xml>
<
codeModifier type="
codeFragment">
<
text>
if( i == 0 ) {</
text>
<
text>
printf("ASSERT ERROR!!");</
text>
<
text>
}</
text>
</
codeModifier>
</
xd:
xml>
<
h3>
Modified Code</
h3>
<
div class="
source">
<
pre>
int foo( int i )
<
span class="
highlightedCode">
if( i == 0 ) {
printf("ASSERT ERROR!!");
}</
span>
return 200;
}</
pre>
</
div>
<
xd:
weaverRuleLinks pointcutType="
src:comment"
adviceType="
replace"
codeModifierType="
codeFragment" />
</
xd:
detail>
<
xd:
cvsId>
$Id$</
xd:
cvsId>
<
xd:
author>
ibirrer</
xd:
author>
<
xd:
copyright>
2004, P&P Software GmbH</
xd:
copyright>
</
xd:
doc>
<
xd:
doc>
Replaces a comment element with a code fragment.
If the comment 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:comment[ax:advice[@type='replace' and position() = 1]/ax:codeModifier[@type='codeFragment']]"
mode="
weaving">
<!---->
<
xsl:
if test="
count(ax:advice[@type='replace']) > 1">
<
xsl:
message terminate="
yes">
[ERROR] comment_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) > 1">
<!---->
<
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>
<!---->
<!---->
<
xsl:
variable name="
indent"
select="
util:repeatString($defaultIndentation, count(ancestor::src:block) + 1 - count(parent::src:block))" />
<!---->
<
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