473,651 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing node set through document function to extension object

Code sample below demonstrates following:
We have sample extension object with 2 methods
TestMethod - takes XPathNodeIterat or as a parameter
TestMethod2 - takes string as a parameter
also we have CustomXmlResolv er, stylesheet takes <XML>SourceDo c</XML> as
source XML document
also sylesheet retreives <XML>CustomXmlR esolverData</XML> XML document
through the document function and CustomXmlResolv er
now we pass $externalDoc/XML node set to both, TestMothod and TestMethod2
I expect output like "CustomXmlResol verData_____Cus tomXmlResolverD ata" but
it outputs "SourceDoc_Cust omXmlResolverDa ta" !!!
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.XPat h;
using System.Xml.Xsl;

namespace TestApp
{
public class MainClass
{
public MainClass()
{
}
[STAThread]
static void Main(string[] args)
{
XsltArgumentLis t arg = new XsltArgumentLis t();
arg.AddExtensio nObject("testur i", new SampleExtension Object());
XslTransform t = new XslTransform();

XPathDocument styleSheet = new XPathDocument(n ew StringReader(
"<xsl:styleshee t version=\"1.0\"
xmlns:xsl=\"htt p://www.w3.org/1999/XSL/Transform\" xmlns:eo=\"test uri\">" +
"<xsl:varia ble name=\"external Doc\" select=\"docume nt('uriuriuri') \"/>" +
"<xsl:templ ate match=\"/\">" +
"<xsl:value-of select=\"eo:Tes tMethod($extern alDoc/XML)\"/>___" +
"<xsl:value-of select=\"eo:Tes tMethod2($exter nalDoc/XML)\"/>" +
"</xsl:template>" +
"</xsl:stylesheet> "

));
t.Load(styleShe et.CreateNaviga tor(), null,
typeof(MainClas s).Assembly.Evi dence);

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

t.Transform(src Doc, arg, Console.Out, new CustomXmlResolv er());

}
}
class CustomXmlResolv er : System.Xml.XmlR esolver
{
public override object GetEntity(Uri absoluteUri, string role, Type
ofObjectToRetur n)
{
return new
MemoryStream(En coding.Default. GetBytes("<XML> CustomXmlResolv erData</XML>"));
}
public override System.Net.ICre dentials Credentials
{
set
{
}
}
}
class SampleExtension Object
{
public string TestMethod(XPat hNodeIterator it)
{
XPathNavigator nav = it.Current;
return nav.Value;
}
public string TestMethod2(str ing s)
{
return s;
}

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


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

public string TestMethod(XPat hNodeIterator 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!P LEASEtkachenko. com> wrote in message
news:eY******** ******@tk2msftn gp13.phx.gbl...
Oleksandr Brovko wrote:

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

Thank you, this was the case. I would have read MSDN closely :)
----- MSDN: ----
XPathNodeIterat or.Current Property [C#]
Note The XPathNodeIterat or is initially positioned on the context node from
which the node set was selected. MoveNext must be called to move the
XPathNodeIterat or 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
3421
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
42859
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. e.g. aTextBox=document.createElement('input'); aTextBox.onchange=calculateOneRow2;
3
14927
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) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
4
2484
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 with my html code: var nodeToReplaceWith = document.createElement("<SPAN>"); nodeToReplaceWith.innerHTML = HTMLCodeToReplaceWith; node.replaceNode(nodeToReplaceWith);
8
2214
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, having limited experience with hacking out JavaScript but no serious coding with it. I do have programming experience though. The logic seems fine to me. Is there something I'm missing? <script type="text/javascript"> var out = "";
6
2007
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 the make of the car. But then I pass a specific node from xmlDoc into another function, not the whole xmlDoc, just a node from it. And if I run an xpath against it, I have to use .// (has a period at the beginning) so it does not grab info from...
4
2375
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. Because I want to use some ajax-requests and other javascript-functions on my xhtml, I need to dynamically add event handlers to any possible dom-elements. All solutions I found so fare are for specific, pre-known
10
13010
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 boldLink=document.getElementById('cmtbold');
10
8791
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: org.w3c.dom.DOMException: NOT_SUPPORTED_ERR: The implementation does not support the requested type of object or operation. at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source) at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source)
0
8352
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
8579
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
7297
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...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
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
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.