473,397 Members | 1,961 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,397 software developers and data experts.

passing node set through document function to extension object

Code sample below demonstrates following:
We have sample extension object with 2 methods
TestMethod - takes XPathNodeIterator as a parameter
TestMethod2 - takes string as a parameter
also we have CustomXmlResolver, stylesheet takes <XML>SourceDoc</XML> as
source XML document
also sylesheet retreives <XML>CustomXmlResolverData</XML> XML document
through the document function and CustomXmlResolver
now we pass $externalDoc/XML node set to both, TestMothod and TestMethod2
I expect output like "CustomXmlResolverData_____CustomXmlResolverDa ta" but
it outputs "SourceDoc_CustomXmlResolverData" !!!
Source document was passed to TestMethod instead of node set returned by the
document function!

I tested this on .Net Framework 1.1.4322 SP1
--- Source ---
using System;
using System.Text;
using System.IO;
using System.Xml.XPath;
using System.Xml.Xsl;

namespace TestApp
{
public class MainClass
{
public MainClass()
{
}
[STAThread]
static void Main(string[] args)
{
XsltArgumentList arg = new XsltArgumentList();
arg.AddExtensionObject("testuri", new SampleExtensionObject());
XslTransform t = new XslTransform();

XPathDocument styleSheet = new XPathDocument(new StringReader(
"<xsl:stylesheet version=\"1.0\"
xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:eo=\"testuri\">" +
"<xsl:variable name=\"externalDoc\" select=\"document('uriuriuri')\"/>" +
"<xsl:template match=\"/\">" +
"<xsl:value-of select=\"eo:TestMethod($externalDoc/XML)\"/>___" +
"<xsl:value-of select=\"eo:TestMethod2($externalDoc/XML)\"/>" +
"</xsl:template>" +
"</xsl:stylesheet>"

));
t.Load(styleSheet.CreateNavigator(), null,
typeof(MainClass).Assembly.Evidence);

XPathDocument srcDoc = new XPathDocument(new
StringReader("<XML>SourceDoc</XML>"));

t.Transform(srcDoc, arg, Console.Out, new CustomXmlResolver());

}
}
class CustomXmlResolver : System.Xml.XmlResolver
{
public override object GetEntity(Uri absoluteUri, string role, Type
ofObjectToReturn)
{
return new
MemoryStream(Encoding.Default.GetBytes("<XML>Custo mXmlResolverData</XML>"));
}
public override System.Net.ICredentials Credentials
{
set
{
}
}
}
class SampleExtensionObject
{
public string TestMethod(XPathNodeIterator it)
{
XPathNavigator nav = it.Current;
return nav.Value;
}
public string TestMethod2(string s)
{
return s;
}

}
}
Nov 12 '05 #1
2 2817
Oleksandr Brovko wrote:
public string TestMethod(XPathNodeIterator it)
{
XPathNavigator nav = it.Current;
return nav.Value;
}


As always with XPathNodeIterator class you have to call MoveNext()
method before accessing Current property:

public string TestMethod(XPathNodeIterator it)
{
if (it.MoveNext()) {
XPathNavigator nav = it.Current;
return nav.Value;
}
else {
//Empty nodeset passed
return "";
}
}
--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #2

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
Oleksandr Brovko wrote:

As always with XPathNodeIterator class you have to call MoveNext() method
before accessing Current property:

Thank you, this was the case. I would have read MSDN closely :)
----- MSDN: ----
XPathNodeIterator.Current Property [C#]
Note The XPathNodeIterator is initially positioned on the context node from
which the node set was selected. MoveNext must be called to move the
XPathNodeIterator to the first node in the selected set.


Nov 12 '05 #3

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

Similar topics

3
by: Seung-Uk Oh | last post by:
Hi, everyone! We are developing an application using both C and C++. We have defined a structure in a C program as follows: typedef struct node { struct node *next; int value; }List;
2
by: kie | last post by:
hello, when i create elements and want to assign events to them, i have realised that if the function assigned to that element has no parameters, then the parent node values can be attained. ...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
4
by: Lukasz Indyk | last post by:
hello;) i have a piece of html code, and want to replace every image on my page with this code. now i do it by replacing IMG node with SPAN node, and then setting innerHTML property of SPAN node...
8
by: Ryan Stewart | last post by:
Putting the following code in a page seems to make it go into an infinite loop unless you give it a very simple node to work with. Either that or it's very very slow. I'm somewhat new to this,...
6
by: Derek Hart | last post by:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I run xpath statements against the xml file to grab data from it, so I use, as an example, //Vehicles/Vehicles/@make to get...
4
by: simon | last post by:
hi, I would like to separate my javascript completely from my xhtml. in the end there should be only <script type="text/javascript" src="javalib.js"></script> in the head-tag to my javascript....
10
by: Janus | last post by:
Hi, Is there a way to pass arguments to the callback function used inside an addEventListener? I see that I can only list the name of the callback function. For eg, I use this: var...
10
by: Simon Brooke | last post by:
The DOM API has included public Node importNode(Node,boolean) as a method of the Document interface for a long time. Does anything actually implement it? Xerces 2 is giving me: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
0
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...

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.