<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"> <xsl:output method="text"/> <xsl:variable name="products"> <product cost="90" price="100"/> <product cost="100"/> <product cost="100" price="90"/> </xsl:variable> <xsl:template match="/"> <xsl:variable name="prices"> <xsl:for-each select="$products/product"> <xsl:choose> <xsl:when test="@price"> <xsl:sequence select="xs:decimal(@price)"/> </xsl:when> <xsl:otherwise> <xsl:sequence select="xs:decimal(@cost) * 1.5"/> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:variable> <xsl:text>Prices: </xsl:text> <xsl:value-of select="$prices" separator=", "/> <xsl:text> Or: </xsl:text> <xsl:value-of separator=", " select="for $p in $products/product return if ($p/@price) then xs:decimal($p/@price) else (xs:decimal($p/@cost) * 1.5)"/> </xsl:template> </xsl:stylesheet>