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() =
> (( $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() < $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");