Register  Login       Search  
Forum  
 
  
 
Forum  Forum     
 
SearchForum Home
  Mvp.Xml Project  EXSLT.NET  Error using dat...
 Error using date functions [Extension function not found: add]
 
sberry
3 posts
Joined
1/12/2006

Error using date functions [Extension function not found: add]
Posted: 12 Jan 06 8:06 PM (Australia)

I am unable to use any of the date functions. I keep receiving errors along the lines of :

expr.SetContext(ctxt)' threw an exception of type 'System.Xml.XPath.XPathException'
base {System.SystemException}: {"Extension function not found: add"}
Message: "Extension function not found: add"

Here is the source code that reproduces it when clean installed (adapted from this MSDN article, with a new date field called launchedDate added)

 

public static string datequery = "date:add(/books/@launchedTime, 'P10D')";

private static void TestXPathDocument()

{

Console.WriteLine("BEGIN: Testing XPathDocument...");
XPathDocument doc = new XPathDocument(@"c:\temp\ConsoleApplication1\ConsoleApplication1\books.xml");
XPathNavigator nav;
XPathExpression expr;
ExsltContext ctxt;
nav = doc.CreateNavigator();
expr = nav.Compile(datequery);
ctxt =
new ExsltContext(nav.NameTable);
expr.SetContext(ctxt);
Console.WriteLine("Date function result {0}", nav.Evaluate(expr));
Console.WriteLine("END: Testing XPathDocument...");
}

olegt
85 posts
www.xmllab.net
Joined
2/25/2005

Re: Error using date functions [Extension function not found: add]
Posted: 19 Jan 06 3:49 AM (Israel)
Sorry for the delay - this is the first topic in this forum so I got no mail notification.

Well, the problem is that date:add() function is defined as date:add(string, string), while you pass attribute node as first argument and EXSLT.NET isn't smart enough to convert it to string. I'll fix it for the next release.
Currently you need to convert arguments to string explicitly using string() function:

date:add(string(/books/@launchedTime), 'P10D')

Oleg Tkachenko, Microsoft MVP for XML, MCPD
http://www.XmlLab.Net | http://blog.tkachenko.com
sberry
3 posts
Joined
1/12/2006

Re: Error using date functions [Extension function not found: add]
Posted: 19 Jan 06 4:23 PM (Australia) Modified By sberry  on 1/19/2006 4:25:16 PM)

Thanks Oleg, that did the trick,

The other question I had was to do with the data type the method returns. You get back a duration data type, which is very nice, however functions for manipulating Duration's are only available in XPath 2.0. What I wanted to do is if the duration is greater than 4 days, then do something.

The function days-from-duration would be ideal. How do you deal with duration data types without these kind of functions?

Is it the intention of MvpXml to include some XPath 2.0 functionality or only EXSLT?

olegt
85 posts
www.xmllab.net
Joined
2/25/2005

Re: Error using date functions [Extension function not found: add]
Posted: 22 Jan 06 8:17 AM (Israel)

I believe you can use date:seconds() to compare durations, something like this:

<xsl:if test="date:seconds($my-duration) > date:seconds('P4D')">way too long</xsl:if>

Haven't tested it though.

About XPath 2.0 - yes, there are plans to include bits of XPath 2.0 and XSLT 2.0, but one piece at a time as we have really limited developer resources.

 


Oleg Tkachenko, Microsoft MVP for XML, MCPD
http://www.XmlLab.Net | http://blog.tkachenko.com
sberry
3 posts
Joined
1/12/2006

Re: Error using date functions [Extension function not found: add]
Posted: 23 Jan 06 5:55 PM (Australia)
Thanks for your help
  Mvp.Xml Project  EXSLT.NET  Error using dat...
Forum Home  Search