0

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?

user1153896
  • 293
  • 7
  • 17
  • I suggest you start using the proper class first, since XslTransform has been deprecated ages ago: http://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.aspx Unfortunately, XPATH does not have the abs() function, but it can be easily derived. – Mihai Todor May 23 '12 at 16:48

2 Answers2

5

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.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
-1

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?

Community
  • 1
  • 1
yand38
  • 7
  • 1