473,769 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BUG in xsltTransform.L oad: 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.XPa th.XPathExcepti on: 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:styleshe et version="1.0" xmlns:http="urn :extended-xlt" xmlns:ms="urn:s chemas-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(stri ng xsltLocation)

{

try

{

XslTransform tmpXslt = new XslTransform();

XPathDocument tmpxpathDoc = new XPathDocument(x sltLocation);

clsXmlResolver ovrXmlResolver = new clsXmlResolver( );

tmpXslt.Load(tm pxpathDoc, ovrXmlResolver, null);

}

catch (Exception ex)

{

MessageBox.Show (ex.ToString()) ;

}

}

private void Form1_Load(obje ct sender, System.EventArg s e)

{

FirstTrial("tem plate.xslt");

}

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


I have managed to simplify your bug case to just

<xsl:styleshe et 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. XsltCompileExce ption: (4,10) :
---> System.Xml.Xsl. XsltException: '($var)*2' is an invalid XPath
expression. ---> System.Xml.XPat h.XPathExceptio n: XsltContext is needed for
this query because of an unknown function.
at System.Xml.XPat h.VariableQuery .ReturnType()
at System.Xml.XPat h.GroupQuery.Re turnType()
at System.Xml.XPat h.NumericExpr.. ctor(Op op, IQuery opnd1, IQuery opnd2)
at System.Xml.XPat h.QueryBuilder. ProcessOperator (Operator root, IQuery
qyInput, Boolean& cache, Boolean& position)
at System.Xml.XPat h.QueryBuilder. ProcessNode(Ast Node root, IQuery qyInput,
Int32 parent, AxisType parentaxis, Boolean& cache, Boolean& position)
at System.Xml.XPat h.QueryBuilder. Build(AstNode root, String query)
at System.Xml.Xsl. Compiler.AddQue ry(String xpathQuery, Boolean allowVar,
Boolean allowKey)
--- End of inner exception stack trace ---
at System.Xml.Xsl. Compiler.AddQue ry(String xpathQuery, Boolean allowVar,
Boolean allowKey)
at System.Xml.Xsl. ValueOfAction.C ompileAttribute (Compiler compiler)
at System.Xml.Xsl. CompiledAction. CompileAttribut es(Compiler compiler)
at System.Xml.Xsl. ValueOfAction.C ompile(Compiler compiler)
at System.Xml.Xsl. Compiler.Create ValueOfAction()
at System.Xml.Xsl. ContainerAction .CompileInstruc tion(Compiler compiler)
at System.Xml.Xsl. ContainerAction .CompileOnceTem plate(Compiler compiler)
at System.Xml.Xsl. ContainerAction .CompileTemplat e(Compiler compiler)
at System.Xml.Xsl. TemplateAction. Compile(Compile r compiler)
at System.Xml.Xsl. Compiler.Create TemplateAction( )
at System.Xml.Xsl. ContainerAction .CompileTopLeve lElements(Compi ler compiler)
at System.Xml.Xsl. ContainerAction .CompileDocumen t(Compiler compiler,
Boolean inInclude)
at System.Xml.Xsl. RootAction.Comp ile(Compiler compiler)
at System.Xml.Xsl. Compiler.Create RootAction()
at System.Xml.Xsl. Compiler.Compil e(NavigatorInpu t input, XmlResolver
xmlResolver)
--- End of inner exception stack trace ---
at System.Xml.Xsl. Compiler.Compil e(NavigatorInpu t input, XmlResolver
xmlResolver)
at System.Xml.Xsl. XslTransform.Co mpile(XPathNavi gator stylesheet,
XmlResolver resolver)
at System.Xml.Xsl. XslTransform.Lo ad(XmlReader stylesheet)
at Test.Main(Strin g[] args) in d:\projects\tes t2\class1.cs:li ne 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.XP ath.XPathExcept ion:
XsltContext is needed for this query because of an unknown function." *

I have managed to simplify your bug case to just

<xsl:styleshe et 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_P LEASEtkachenko. com> wrote in message
news:Oh******** ********@TK2MSF TNGP09.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.XP ath.XPathExcept ion:
XsltContext is needed for this query because of an unknown function." *

I have managed to simplify your bug case to just

<xsl:styleshe et 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
2968
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 is to fifo pipe network syslog into a MySQL database backend. The php scripts reference the database, and print stuff to the screen. My Info -> RH9.0 , MySQL 4.0.14, apache1.3.28 I have successfully gotten everything installed, compiled, etc....
1
20612
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 = "c:/php/extensions/" But I am still getting the error that it can't find the php_mhash.dll though I can see that it is indeed in the folder.
9
13903
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(), below the description of this function from MySQL manual. Anybody can help me with this ?? I think that PLPGSQL language can be used or maybe other (plPerl) etc.
9
21651
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 the results in the grid. Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message...
4
302
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 states: "Operation must use an updateable query" I know it has to do with the update command on the OleDbDataAdapter. I've tried looking for the problem on the net and newsgroups but I don't seem to have the same problems as everyone else. Please,...
1
1803
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 I'd like to auto-load prepared queries this way too. I've figured out how to use pltcu to auto-load a global variable and access that variable by appending the following lines to unknown.pltcl: global var1 set var1 abc
12
2642
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 or numeric. I need a function that will return the requested 'part' of the contents of the field. A 'part' would be defined as consecutive Alpha or Numeric characters in the text field. Examples: Field Name = cFoo
1
2847
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 with it. So, on Redhat, we have two versions of PHP - Apache uses 4.3.9, there's also a 4.4.2 that is default from command-line. 4.3.9 was installed by RPM, 4.4.2 was built from source. I can get mysql.so loaded and working fine in 4.4.2, but...
1
7857
by: jesmi | last post by:
my code is: U]employee.cfm <html> <head> <title>Employee List</title> </head> <body> <h1>Employee List</h1>
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.