473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

BUG in xsltTransform.Load: XsltContext is needed for this query because of an unknown function.

When Trying to Load an XSLT File with the XslTransform i got a rather annoying Exception being thrown "System.Xml.XPath.XPathException: XsltContext is needed for this query because of an unknown function."
It was annoying because I had checked created the whole document and tested it in Internet Explorer 6.0 and everything worked perfectly; no errors or warnings.
After doing research i found out that most often times the error that i was receiving should only be given upon a Transformation or Select Node and is solved by providing an XSLtcontext to resolve custom functions and in some cases functions like position etc.
After alot of debugging i pinned it down to one section [( position() > (( $cur-page ) * $no-rows * $no-cols) )]" (note I have since shortened it as it was about 3 times longer then this. I just identified this as the "offending section". Now one thing that I will note there is an extra pair of Parentheses around $cur-page. As i rememember this was done because at some time during the creation process I received a strange error that was similar to the "unknown" function and for some reason putting the parentheses around it solved the problem and thus was forgotten.
changing
[( position() > (( $cur-page ) * $no-rows * $no-cols) )]" - which is Perfectly valid in IE 6.0 and Mozilla/Firebird was causing the Exception to be thrown. After Playing around with it a bit as i had a piece of logic very similar to this one that was perfectly fine i went and put - 0 in and it worked fine
so
[( position() > (( $cur-page ) * $no-rows * $no-cols) )]" - Fine in IE Errors in C#.NET
[( position() > ( $cur-page * $no-rows * $no-cols) )]" - Fine in IE - fine in C#
[( position() > (( $cur-page - 0 ) * $no-rows * $no-cols) )]" - Fine in IE - Fine in C#

In Conclusion: I do not know if this is a design by nature, a bug or what not. All i know is it caused me a great deal of headache trying to figure it out. And as i stated before while the extra parantheses were not needed they were there due to another strange error that I had been getting earlier in the stage of developing.

Here is a Sample XSLT File
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:http="urn:extended-xlt" xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="no-cols" select="root/Images/@across" />

<xsl:param name="no-rows" select="root/Images/@down" />

<xsl:param name="cur-page" select="root/CurrentPage/@value" />

<xsl:template match="/">

<xsl:apply-templates select="root/Images/file[( position() &gt; (( $cur-page ) * $no-rows * $no-cols) )]" mode="new-row"/>

</xsl:template>

<xsl:template match="file" mode="new-row">

<tr>

<xsl:apply-templates select=". | following-sibling::file[position() &lt; $no-cols]"/>

</tr>

</xsl:template>

<xsl:template match="file">

<td>

<a href="#" title="|{@name}|"><img src="Snapshot - MSN Messenger Beta.JPG" /></a>

</td>

</xsl:template>

</xsl:stylesheet>

Sample C# Code being used

public void FirstTrial(string xsltLocation)

{

try

{

XslTransform tmpXslt = new XslTransform();

XPathDocument tmpxpathDoc = new XPathDocument(xsltLocation);

clsXmlResolver ovrXmlResolver = new clsXmlResolver();

tmpXslt.Load(tmpxpathDoc, ovrXmlResolver, null);

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

}

private void Form1_Load(object sender, System.EventArgs e)

{

FirstTrial("template.xslt");

}

Nov 11 '05 #1
3 5186
Torrent wrote:
When Trying to Load an XSLT File with the XslTransform i got a rather
annoying Exception being thrown *"System.Xml.XPath.XPathException:
XsltContext is needed for this query because of an unknown function." *


I have managed to simplify your bug case to just

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:variable name="var" select="3"/>
<xsl:value-of select="($var)*2"/>
</xsl:template>
</xsl:stylesheet>

Runnig under 1.0 and 1.1 it throws:
System.Xml.Xsl.XsltCompileException: (4,10) :
---> System.Xml.Xsl.XsltException: '($var)*2' is an invalid XPath
expression. ---> System.Xml.XPath.XPathException: XsltContext is needed for
this query because of an unknown function.
at System.Xml.XPath.VariableQuery.ReturnType()
at System.Xml.XPath.GroupQuery.ReturnType()
at System.Xml.XPath.NumericExpr..ctor(Op op, IQuery opnd1, IQuery opnd2)
at System.Xml.XPath.QueryBuilder.ProcessOperator(Oper ator root, IQuery
qyInput, Boolean& cache, Boolean& position)
at System.Xml.XPath.QueryBuilder.ProcessNode(AstNode root, IQuery qyInput,
Int32 parent, AxisType parentaxis, Boolean& cache, Boolean& position)
at System.Xml.XPath.QueryBuilder.Build(AstNode root, String query)
at System.Xml.Xsl.Compiler.AddQuery(String xpathQuery, Boolean allowVar,
Boolean allowKey)
--- End of inner exception stack trace ---
at System.Xml.Xsl.Compiler.AddQuery(String xpathQuery, Boolean allowVar,
Boolean allowKey)
at System.Xml.Xsl.ValueOfAction.CompileAttribute(Comp iler compiler)
at System.Xml.Xsl.CompiledAction.CompileAttributes(Co mpiler compiler)
at System.Xml.Xsl.ValueOfAction.Compile(Compiler compiler)
at System.Xml.Xsl.Compiler.CreateValueOfAction()
at System.Xml.Xsl.ContainerAction.CompileInstruction( Compiler compiler)
at System.Xml.Xsl.ContainerAction.CompileOnceTemplate (Compiler compiler)
at System.Xml.Xsl.ContainerAction.CompileTemplate(Com piler compiler)
at System.Xml.Xsl.TemplateAction.Compile(Compiler compiler)
at System.Xml.Xsl.Compiler.CreateTemplateAction()
at System.Xml.Xsl.ContainerAction.CompileTopLevelElem ents(Compiler compiler)
at System.Xml.Xsl.ContainerAction.CompileDocument(Com piler compiler,
Boolean inInclude)
at System.Xml.Xsl.RootAction.Compile(Compiler compiler)
at System.Xml.Xsl.Compiler.CreateRootAction()
at System.Xml.Xsl.Compiler.Compile(NavigatorInput input, XmlResolver
xmlResolver)
--- End of inner exception stack trace ---
at System.Xml.Xsl.Compiler.Compile(NavigatorInput input, XmlResolver
xmlResolver)
at System.Xml.Xsl.XslTransform.Compile(XPathNavigator stylesheet,
XmlResolver resolver)
at System.Xml.Xsl.XslTransform.Load(XmlReader stylesheet)
at Test.Main(String[] args) in d:\projects\test2\class1.cs:line 28
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
Oleg Tkachenko wrote:
Torrent wrote:
When Trying to Load an XSLT File with the XslTransform i got a rather
annoying Exception being thrown *"System.Xml.XPath.XPathException:
XsltContext is needed for this query because of an unknown function." *

I have managed to simplify your bug case to just

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:variable name="var" select="3"/>
<xsl:value-of select="($var)*2"/>
</xsl:template>
</xsl:stylesheet>


Forgot to say: a workaround is to remove (superfluous anyway) parentheses
around a variable reference:
$cur-page * $no-rows * $no-cols
instead of
( $cur-page ) * $no-rows * $no-cols
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3
Yep. As I pointed out. I only took the time to post it afterwards because
even though they were superflous and after the whole thing was done it still
imho is a bug
"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:Oh****************@TK2MSFTNGP09.phx.gbl...
Oleg Tkachenko wrote:
Torrent wrote:
When Trying to Load an XSLT File with the XslTransform i got a rather
annoying Exception being thrown *"System.Xml.XPath.XPathException:
XsltContext is needed for this query because of an unknown function." *

I have managed to simplify your bug case to just

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:variable name="var" select="3"/>
<xsl:value-of select="($var)*2"/>
</xsl:template>
</xsl:stylesheet>


Forgot to say: a workaround is to remove (superfluous anyway) parentheses
around a variable reference:
$cur-page * $no-rows * $no-cols
instead of
( $cur-page ) * $no-rows * $no-cols
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Erich Trowbridge | last post by:
Has anybody seen this tool? It is awesome. check out http://vw.vermeer.org/ . It's a php front end for large-scale syslog deployments. It makes managing syslog in large networks a snap. The idea...
1
by: Stefan | last post by:
Hi, I just downloaded PHP-4.3.3 for win32 and got the extensions folder and dropped it intot he root of the PHP directory and set it's path in the PHP.ini: extension_dir =...
9
by: Marek Lewczuk | last post by:
Hello, I'm moving out from MySQL to PostgreSQL and there are some function which are not supported in PG so I'm trying to write my own functions. Currently I have big problem with function IF(),...
9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
4
by: Derek Van Cuyk | last post by:
Hi everyone! I'm trying to write a web application in school that utilizes a MS Access database. I can read and everything fine from it but when I try to add a new record I get an exception that...
1
by: Craig Addleman | last post by:
How do I use the pltcu unknown module to auto-load a return value from a select query? I'm trying to boost performance in our databases by preloading certain frequently-used variables. Ultimately...
12
by: Ima Loozer | last post by:
OK folks here is what I need help with. Lets assume I have a text field that will contain AlphaNumeric data. There is no set pattern to the field such that any given character can be either alpha...
1
by: edfialk | last post by:
Hi all, I'm desperately trying to get a simple mysql connection working in php 4.3.9 and I think I have a doozy for you guys. First of all, I didn't set up ANY of this system, I'm just working...
1
by: jesmi | last post by:
my code is: U]employee.cfm <html> <head> <title>Employee List</title> </head> <body> <h1>Employee List</h1>
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.