all groups > dotnet xml > september 2003 >
You're in the

dotnet xml

group:

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


BUG in xsltTransform.Load: XsltContext is needed for this query because of an unknown function. Torrent
9/28/2003 3:38:47 PM
dotnet xml:
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."=20
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.=20
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.=20
changing=20
[( 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=20
[( 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.=20

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

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

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

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

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

<xsl:template match=3D"/">

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

</xsl:template>

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

<tr>

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

</tr>

</xsl:template>

<xsl:template match=3D"file">

<td> =20

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

</td>

</xsl:template>

</xsl:stylesheet>

Sample C# Code being used

public void FirstTrial(string =
xsltLocation)

{

try

{

XslTransform =
tmpXslt =3D new XslTransform();

XPathDocument =
tmpxpathDoc =3D new XPathDocument(xsltLocation);

clsXmlResolver =
ovrXmlResolver =3D new clsXmlResolver();

=
tmpXslt.Load(tmpxpathDoc, ovrXmlResolver, null);

}

catch (Exception ex)=20

{

=
MessageBox.Show(ex.ToString());

}

}

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

{

FirstTrial("template.xslt");

Re: BUG in xsltTransform.Load: XsltContext is needed for this query because of an unknown function. Oleg Tkachenko
9/29/2003 11:55:14 AM
[quoted text, click to view]

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(Operator 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(Compiler compiler)
at System.Xml.Xsl.CompiledAction.CompileAttributes(Compiler 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(Compiler compiler)
at System.Xml.Xsl.TemplateAction.Compile(Compiler compiler)
at System.Xml.Xsl.Compiler.CreateTemplateAction()
at System.Xml.Xsl.ContainerAction.CompileTopLevelElements(Compiler compiler)
at System.Xml.Xsl.ContainerAction.CompileDocument(Compiler 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
Re: BUG in xsltTransform.Load: XsltContext is needed for this query because of an unknown function. Oleg Tkachenko
9/29/2003 12:21:00 PM
[quoted text, click to view]

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
Re: BUG in xsltTransform.Load: XsltContext is needed for this query because of an unknown function. Torrent
9/29/2003 2:29:48 PM
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


[quoted text, click to view]

AddThis Social Bookmark Button