Controlling whitespace in the output is often a problem. A solution: remove all whitespace and then add whitespace back in as required
<xsl:variable name="newline"><xsl:text> </xsl:text></xsl:variable> <xsl:variable name="space"><xsl:text> </xsl:text></xsl:variable> <xsl:variable name="tab"><xsl:text>	</xsl:text></xsl:variable> <xsl:value-of select="$newline" /> <xsl:value-of select="$space" /> <xsl:value-of select="$tab" />
Calculating values for reuse several times. You need the absolute value of an XML fragment:
<num>-620</num> <xsl:variable name="absnum"> <xsl:choose> <xsl:when test="0 > num"><xsl:value-of select="0 - num"/></xsl:when> <xsl:otherwise><xsl:value-of select="num"/></xsl:otherwise> </xsl:choose> </xsl:variable>