<
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: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 add an access modifer block to a class. </
xd:
short>
<
xd:
detail>
<
ul>
<
li>
srcML element: <
code>
src:class</
code></
li>
<
li>
advice type: <
code>
add</
code></
li>
<
li>
codeModifier type: <
code>
accessModifierBlock</
code></
li>
</
ul>
<
h2>
Example 1</
h2>
<
h3>
Base Code</
h3>
<
div class="
source">
<
pre>
class Foo {
}</
pre>
</
div>
<
h3>
Code Modifier</
h3>
<
xd:
xml>
<
codeModifier type="
accessModifierBlock">
<
accessModifierBlock type="
public" />
</
codeModifier>
</
xd:
xml>
<
h3>
Modified Code</
h3>
<
div class="
source">
<
pre>
class Foo {
<
span class="
highlightedCode">
public:</
span>
}</
pre>
</
div>
<
xd:
weaverRuleLinks pointcutType="
src:class"
adviceType="
add"
codeModifierType="
accessModifierBlock" />
</
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>
Apply tempates with mode <
code>
weaving_class_add_accessModifierBlock</
code>
to all (excludig advice elements) <
code>
src:class</
code>
child elements.
</
xd:
doc>
<
xsl:
template match="
src:class[ax:advice[@type='add' and position() = 1]/ax:codeModifier[@type='accessModifierBlock']]"
mode="
weaving">
<
xsl:
copy>
<
xsl:
copy-of select="
@*" />
<!---->
<
xsl:
copy-of select="
ax:advice[position() != 1]" />
<!---->
<
xsl:
apply-templates select="
node()[not(self::ax:advice)]"
mode="
weaving_class_add_accessModifierBlock">
<
xsl:
with-param name="
advice"
select="
ax:advice[1]" />
</
xsl:
apply-templates>
</
xsl:
copy>
</
xsl:
template>
<
xd:
doc>
Template for the function block.
<
xd:
param name="
advice"
type="
node-set">
The advice element which will be used for weaving the function.</
xd:
param>
</
xd:
doc>
<
xsl:
template match="
src:block"
mode="
weaving_class_add_accessModifierBlock">
<
xsl:
param name="
advice" />
<
xsl:
copy>
<
xsl:
copy-of select="
@*" />
<
xsl:
call-template name="
addElementsAtEndOfBlock">
<!---->
<
xsl:
with-param name="
indent"
select="
''" />
<
xsl:
with-param name="
block"
select="
." />
<
xsl:
with-param name="
elements">
<
xsl:
for-each select="
$advice/ax:codeModifier/ax:accessModifierBlock">
<
xsl:
choose>
<
xsl:
when test="
@type='private'">
<
src:
private>
private:</
src:
private>
</
xsl:
when>
<
xsl:
when test="
@type='protected'">
<
src:
protected>
protected:</
src:
protected>
</
xsl:
when>
<
xsl:
when test="
@type='public'">
<
src:
public>
public:</
src:
public>
</
xsl:
when>
</
xsl:
choose>
<
xsl:
if test="
position() != last()">
<
xsl:
text>
</
xsl:
text>
</
xsl:
if>
</
xsl:
for-each>
</
xsl:
with-param>
</
xsl:
call-template>
</
xsl:
copy>
</
xsl:
template>
<
xd:
doc>
Default copy template.
</
xd:
doc>
<
xsl:
template match="
*"
mode="
weaving_class_add_accessModifierBlock">
<
xsl:
param name="
advice" />
<
xsl:
copy>
<
xsl:
copy-of select="
@*" />
<
xsl:
apply-templates mode="
weaving_class_add_accessModifierBlock">
<
xsl:
with-param name="
advice"
select="
$advice" />
</
xsl:
apply-templates>
</
xsl:
copy>
</
xsl:
template>
</
xsl:
stylesheet>
v