SO I’ve never used XSLT before, and i’ve only used XPath in it’s simplest form.
I have a Xml element “Earth” with two attributes Stamina and willpower. Both contain numbers.
What I’m trying to do is Display next to the word “Earth” the value of the least of these attributes.
I can’t seem to workout how to call functions in XPath.
Here is my XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
version="2.0">
<!--<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
-->
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="//Rings"/>
</body>
</html>
</xsl:template>
<xsl:template match="//Rings">
<h2>Rings</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Earth</th>
<th>
<xsl:value-of select="fn:min(fn:number(Earth/@*))"/>
</th>
</tr>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
MS Visual Studio comes pre-packaged with the .NET XSLT processor XslCompiledTransform, and this is an XSLT 1.0 processor.
On the other side,
min()is a standard function in XPath 2.0 and not in XPath 1.0. XSLT 1.0 uses only XPath 1.0.An XSLT 1.0 solution to the problem:
when this transformation is applied on the following XML document (as you haven’t provided one!):
the wanted, correct result is produced:
In .NET it is possible to use a third party XSLT 2.0 processor such as Saxon.NET or XQSharp. Below is an XSLT 2.0 solution: