The Velocity macro element is used to create a reusable function that can be called multiple times. See Hannon Hill's Script Format element for macro
The code below will emulate the W3Schools template page for XSLT but adding in a macro to determine if the purchase is a deal. If the CD price is under $9 we call it a deal.
#macro( deal $a )#set ($price = $_MathTool.toDouble($a))
#if( $price <= 9 )
<strong>Deal!</strong>
#end ##IF
#end ##MACRO DEAL
<h2>My CD Collection</h2>
#set($cds = $_XPathTool.selectNodes($contentRoot, '//catalog/cd'))
#foreach($cd in $cds) ##LOOP
#set ($artist = $cd.getChild('artist').value)
#set ($title = $cd.getChild('title').value)
#set ($pricetext = $cd.getChild('price').value)
<p>
Title: <span style="color:#ff0000">$title</span><br />
Artist: <span style="color:#00ff00">$artist</span><br />
Price: $pricetext #deal( $pricetext )<br />
</p>
#end ##LOOP
My CD Collection
Title: Empire Burlesque
Artist: Bob Dylan
Price: 10.90
Title: Hide your heart
Artist: Bonnie Tyler
Price: 9.90
Title: Greatest Hits
Artist: Dolly Parton
Price: 9.90
Title: Still got the blues
Artist: Gary Moore
Price: 10.20
Title: Eros
Artist: Eros Ramazzotti
Price: 9.90
Title: One night only
Artist: Bee Gees
Price: 10.90
Title: Sylvias Mother
Artist: Dr.Hook
Price: 8.10 Deal!
Title: Maggie May
Artist: Rod Stewart
Price: 8.50 Deal!
Title: Romanza
Artist: Andrea Bocelli
Price: 10.80
Title: When a man loves a woman
Artist: Percy Sledge
Price: 8.70 Deal!
Title: Black angel
Artist: Savage Rose
Price: 10.90
Title: 1999 Grammy Nominees
Artist: Many
Price: 10.20
Title: For the good times
Artist: Kenny Rogers
Price: 8.70 Deal!
Title: Big Willie style
Artist: Will Smith
Price: 9.90
Title: Tupelo Honey
Artist: Van Morrison
Price: 8.20 Deal!
Title: Soulsville
Artist: Jorn Hoel
Price: 7.90 Deal!
Title: The very best of
Artist: Cat Stevens
Price: 8.90 Deal!
Title: Stop
Artist: Sam Brown
Price: 8.90 Deal!
Title: Bridge of Spies
Artist: T`Pau
Price: 7.90 Deal!
Title: Private Dancer
Artist: Tina Turner
Price: 8.90 Deal!
Title: Midt om natten
Artist: Kim Larsen
Price: 7.80 Deal!
Title: Pavarotti Gala Concert
Artist: Luciano Pavarotti
Price: 9.90
Title: The dock of the bay
Artist: Otis Redding
Price: 7.90 Deal!
Title: Picture book
Artist: Simply Red
Price: 7.20 Deal!
Title: Red
Artist: The Communards
Price: 7.80 Deal!
Title: Unchain my heart
Artist: Joe Cocker
Price: 8.20 Deal!