To reduce the copy/pasta here I believe you can use http://www.w3.org/TR/xslt#modes (bringing this up because this PR is becoming a tutorial on XSLT ; )   ... writing up some example code...