Does anybody know of a preprocessor for XSLT to make it less verbose? Something like what SASS is to CSS, a little proggy that will take light syntax:
"/":
{
<html>
<head>
<title>My book collection</title>
</head>
<body>
{@ "//media"}
{@ quantity = calc_abs_value("//total_quantity")}
Price : {@ multiply(price:"//item[@selected='true'][@price]",qty :$quantity) }
</body>
</html>
}
"media[@type='book']":
{
<div id="{@id}">
{title} by {author} published in {published_date}
</div>
}
function calc_abs_value(value)
{
if ($value < 0) {- $value} else {$value}
}
function multiply(price,qty:"1")
{
switch
{
"$qty = 1" : $price * $qty
"$qty < 5" : $price * $qty * 0.95
"$price * $qty < 0" : 0
default : 0
}
}
and turn this into far-less readable XSLT:
<xsl:template match="/">
<html>
<head>
<title>My book collection</title>
</head>
<body>
<xsl:apply-templates select="//media" />
<xsl:variable name="quantity"><xsl:call-template name="calc_abs_value">
<xsl:with-param name="value"><xsl:value-of select="//total_quantity" /></xsl:with-param>
</xsl:call-template></xsl:variable>
Price : <xsl:call-template name="multiply">
<xsl:with-param name="price"><xsl:value-of select="//item[@selected='true'][@price]" /></xsl:with-param>
<xsl:with-param name="qty"><xsl:value-of select="$quantity" /></xsl:with-param>
</xsl:call-template>
</body>
</html>
</xsl:template>
<xsl:template match="media[@type='book']">
{
<div id="{@id}">
<xsl:value-of select="title" /> by <xsl:value-of select="author" /> published in <xsl:value-of select="published_date" />
</div>
}
</xsl:template>
<xsl:template name="calc_abs_value">
<xsl:param name="value" />
<xsl:choose>
<xsl:when test="$value < 0">
- <xsl:value-of select="$value" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
I am too lazy to write the XSLT form of multiply but I'm sure you already figured out what I mean.
Or is there an IDE that is more XSLT aware than others, e.g it displays {author}
but expands to:
<xsl:value-of select="author" />
when you click it?