user1153896
user1153896

Reputation: 303

'abs()' is an unknown XSLT function

I have XSLT like:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
.......
<xsl:value-of select="format-number(abs(QUANTITY), '#')"/>
....

which works perfectly with tools like Altova XMLSpy, but when I am trying to do transformation from .Net:

XslTransform myXslTransform = new XslTransform();
myXslTransform.Load("some.xls");
myXslTransform.Transform(@"inputxml", @"c:\out.csv");

It throws exception

System.Xml.Xsl.XsltException was unhandled
  Message='abs()' is an unknown XSLT function.
  Source=System.Data.SqlXml

I know ABS is a simple-enough function to implement, but question is why it happens with .Net?

Does anybody have any thoughts?

Upvotes: 1

Views: 2940

Answers (2)

Martin Honnen
Martin Honnen

Reputation: 167696

The abs function is part of XPath version 2.0 and as that supported in XSLT 2.0 processors like Saxon, AltovaXML and XMLPrime. Microsoft's XSLT processors (MSXML 3, 4, 5, 6, XslTransform, XslCompiledTransform) are all XSLT 1.0 processors that only support the functions defined in XPath 1.0 and XSLT 1.0.

Upvotes: 6

yand38
yand38

Reputation: 7

XMLSpy is providing the function for you, it's not built into XSLT. See this post for the same question (and implementations): XSLT: can we use abs value?

Upvotes: -1

Related Questions