<
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 replaces the contents of a block (Everything inside curly braces) with a code fragment. </
xd:
short>
<
xd:
detail>
<
ul>
<
li>
srcML element: <
code>
src:block</
code>
</
li>
<
li>
advice type: <
code>
around</
code>
</
li>
<
li>
codeModifier type: <
code>
codeFragment</
code>
</
li>
</
ul>
<
h2>
Example 1</
h2>
<
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>
}</
pre>
</
div>
<
h2>
Example 2</
h2>
<
h3>
Base Code</
h3>
<
div class="
source">
<
pre>
int main() {
int i = 0;
int c = 5;
}</
pre>
</
div>
<
h3>
Code Modifier</
h3>
<
p>
The variable <
code>
${ blockBody}</
code>
prints the original body content and indents it with two spaces (defined by the two spaces after <
code>
'${'</
code>
).</
p>
<
xd:
xml>
<
codeModifier type="
codeFragment">
<
text>
try {</
text>
<
text>
${ blockBody}</
text>
<
text>
} catch ( ... ) {</
text>
<
text>
<![CDATA[cout << "ERROR MESSAGE" << endl;]]></
text>
<
text>
}</
text>
</
codeModifier>
</
xd:
xml>
<
h3>
Modified Code</
h3>
<
div class="
source">
<
pre>
int main() {
<
span class="
highlightedCode">
try {</
span>
int i = 0;
int c = 5;
<
span class="
highlightedCode">
} catch (...) {
cout << "ERROR MESSAGE" << endl;
}</
span>
}</
pre>
</
div>
<
xd:
weaverRuleLinks pointcutType="
src:block"
adviceType="
around"
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>
<!---->
<
xsl:
preserve-space elements="
*" />
<
xd:
doc>
Calls named template addAtEndOfBlock provided by XWeaver.</
xd:
doc>
<
xsl:
template match="
src:block[ax:advice[@type='around' and position() = 1]/ax:codeModifier[@type='codeFragment']]"
mode="
weaving">
<
xsl:
copy>
<
xsl:
copy-of select="
@*" />
<!---->
<
xsl:
copy-of select="
ax:advice[position() != 1]" />
<
xsl:
call-template name="
addAtBeginOfBlock">
<
xsl:
with-param name="
block">
<
xsl:
text>
{}</
xsl:
text>
</
xsl:
with-param>
<
xsl:
with-param name="
advice"
select="
ax:advice[1]" />
</
xsl:
call-template>
</
xsl:
copy>
</
xsl:
template>
</
xsl:
stylesheet>
v