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_____CustomXmlResolverData" 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>CustomXmlResolverData</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;
  }

 }
} 


0
shurik (2)
5/16/2005 3:00:07 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
571 Views

Similar Articles

[PageSpeed] 40

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
0
Oleg
5/16/2005 4:37:04 PM
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message 
news:eY4Nq0iWFHA.1152@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.




0
shurik (2)
5/17/2005 8:18:51 AM
Reply:

Similar Artilces:

Passing dates to Sql Server 2005 stored procedure
Hi, I am trying to execute a SQL Stored procedure from Excel using VBA. Apart from 2 string inputs, this proc also accepts two datetime imputs. When these dates are passed via VBA, they are in the format "dd/mm/yyyy. However, the SQL Server does not seem to accept dates passed in this format. Applying different date formats in VBA does not help because eventually when the dates shoot from Excel to SQL Server, they are in the format "dd/mm/yyyy". I don't want to change the regional settings of the machine, since it will only be a temporary solution. This is...

The Same Set of Folders?
I have ten email accounts in WLM. Can I have them download to the same set of folders? This is a multi-part message in MIME format. ------=_NextPart_000_0075_01CA97CA.0C879300 Content-Type: text/plain; charset="Utf-8" Content-Transfer-Encoding: quoted-printable Directly no. WLM does have two methods to accomplish(almost) your request Enable Quick Views(View/Layout/Folder Pane) - right click Quick View icon in left pane and ensure All Inbox is = enabled or If accounts are all pop3, create a rule to move messages after receipt = to on one common folder. ...

Setting up Inventory
I have a workbook and what I am looking to do is, when I put RECEIVED in column "C" I would like it to add Column "C" with the running total of Column "H". If i don't put received in "C" I would like it to subtract the number I put in "E". To summerize I want it to subtract.. but add when i put in Received. Any help would be great I am going to assume that if you dont receive any inventory that you put 0 in column C Do you always subtract column E, or just when there is 0 in Column C? If only when Column C is 0, Column I (or where ...

How to set up search path in MFC?
Under my application folder, there is folder called Driver which has xxx.dll in it. c:\application\Driver My application run in application folder. How to setup the search path in my application so that it can find the xxx.dll in Driver folder? > Under my application folder, there is folder called Driver which has > xxx.dll in it. > > c:\application\Driver > > My application run in application folder. > > How to setup the search path in my application so that it can find the > xxx.dll in Driver folder? I dont follow this. Does your application depend upon this ...

MRP Settings #2
We are trying to use MRP for our Manufacturing and I am facing a problem with some of the settings. There are settings in the MRP defaults where it allows you to specify if you want to Run Reconcile from Manufacturing Orders Run Reconcile from Purchase Orders Run Reconcile from Sales Orders When I try to turn either of these or all of these then I encounter errors. After making these changes, if I enter a Purchase Order and save it, I get an error: [Microsoft] ODBC SQL Server Drive[SQL Server] Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, &...

how do I set automatic insert of day and date
Some of my documents will automatically fill in the day, date when I start typing. Others do not. How can I get this to apply to all my documents? I'm using Word in Microsoft 7. I have been copying the formatting from exsisting documents - maybe something gets lost in the copy. Presumably these documents contain a DATE or CREATEDATE field. I wouldn't advise adding this to the Normal template, but you can add it to specific document templates on which you base new documents. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http:/...

how do i insert a page from a read only pdf document into word
how do i insert a page from a read only pdf document into word without losing reading quality? Word has no ability to handle PDF format documents. The only solutions are to extract the content of the PDF using OCR software such as FineReader or OmniPage, or to insert the first page of the PDF file as an object. (Objects cannot cross page boundaries in Word). If you insert an object it will adapt to the active margins, and as an image this will result in some image impairment. The best you can achieve is to set the layout wrap option of the object to something other than in-line...

Event sink map in non CDialog object?
I think I'm probably asking a very stupid question here, but is it possible to have a generic object (base class CObject) respond to the events of an ActiveX control? That is, to have an event sink map? If so does anyone have an example class or some code to declare this please? I want to encapsulate a 'conversation' with a modem through a comm port, so that all the dialog has to do is say something like modem.sendmessage(strMessage); and the modem object does all of the work. but because my modem class is not a subclass of CDialog, the statement BEGIN_EVENTSINK_MAP(CModem...

Only Service, Settings appear in navigation pane
Using the MSDN subscriber download CRM 3.0 Professional, with the MSDN 10 license key. When I log in using the domain account that was also used to install the server (and then by default was assigned only the role System Administrator), I only see the Service and Settings options in the Navigation pane. I logged in using a different test account, to which the roles Sales, marketing and service were allotted, and that account saw the Sales and Marketing and Service workplace selections. I did assign ALL the roles to my account (the one used to install the server), but I still don'...

How do you set up an account so I can receive email through outlo.
I have an account with netscape but I want to set it up so I can receive it through Outlook. Can I do this, if so how do I do it. Thanks Outlook does not support Netscape mail. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without reading. After searching google.groups.com and finding no answer, Jon asked: | I have an account with netscape but I want to set it up so I can | receive it through Outlook. Can I do this, if so how do I do it....

Using a Public Function 12-08-07
I found a great function to allow me to display my decimals as fractions, but I don't know how to use it? I create reports which then become either work tickets or finished product labels. Where do I put the code. I understand the idea that it should be public so I can use it in any part of my application, but how do I refer to it? Thanks so much. =?Utf-8?B?TGVMZQ==?= <LeLe@discussions.microsoft.com> wrote in news:4FE3E937-4282-4067-92D8-921F44BDBC13@microsoft.com: > I found a great function to allow me to display my decimals as > fractions, but I don't know how ...

Corruption on 2002 / 2000 database showing "blank" objects
Database created in Office XP, used by clients with Office 2000 (database is saved as 2000 format). warning: it's a multi-user environment -- including replication. After few days of usage, the database loses some of the macros and seems to display several empty or blank objects that did not exist previously. Once clicked on receive "object does not exist error". This also appears sometimes in the Reports area, too. Any thoughts? Although Office XP can/does use Access2000 format files, there seems to be a difference depending on which Access it is run under, and that is...

Smartlist's Account Trx should show document dates of submodules
Hi, When you use the Smartlist object Account Transactions and try to find the document date of those transactions coming from the sub modules - Smartlist will not be able to show it. There is a field Document Date, but it will show 00/00/0000. The created date is also not very useful as it takes the system/user date when the transaction was actually posted. Not all the time will the document date be equal to the transaction date. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click ...

How do I link Excel chart axis scale settings to cells?
I want to link a chart's axis scale settings to cells. Is this possible? Hi, You can not directly link the scales setting to cells. Tushar has an addin which help. http://tushar-mehta.com/excel/software/autochart/index.html Cheers Andy strince wrote: > I want to link a chart's axis scale settings to cells. Is this possible? -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info Please ignore...I found the answer in another post. "strince" wrote: > I want to link a chart's axis scale settings to cells. Is this possible? ...

set enable & disable of button (VC 6.0)
Hello, For VC 6.0 (MFC) : How can I set the enable/disable state of that button ? Thanks :) this is not going to work buddy ....... read a book ..... "Eitan M" <no_spam_please@nospam_please.com> wrote in message news:ewfJoieGHHA.1232@TK2MSFTNGP05.phx.gbl... > Hello, > For VC 6.0 (MFC) : > How can I set the enable/disable state of that button ? > > Thanks :) > hi Eitan, Try following, //To Enable button...at run time ...IDB_MYBUTTON is ID of your botton GetDlgItem(IDB_MYBUTTON)->EnableWindow(TRUE); //To Disab...

Creating photo album
Hello, I'm designing a photo-album in MS Publisher that will be printed by a commercial printing-company, and I have some thoughts on how and in what format to save the document. I'm using Adobe Acrobat 6 to make a PDF out of the document. 1. The printing-company want the colors to be CMYK. Where can I make Acrobat store the colors as CMYK? In the settings on tab "Color" I have some options; in the "Color Management Policies" I can choose "Convert all colors to sRGB", but nothing like "Convert all colors to CMYK". So how can I make sure ...

Unlocking a password locked word document
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel I have saved a document ages ago (in 2006) and password locked it. I am unable to open it now because I have forgotten what password I assigned. Is there any way to unlock it? It isn't so much a matter of 'when' you applied the pw as it is a matter of which version of the program was used. Different versions have employed somewhat different methods. Even so, the only thing you can do on your own is keep guessing... There is no "Disregard the Password" button :-) Depending on how critical...

Setting A Number Equal to Another Number
I was wondering if I could set a cell with one number equal to anothe number in another cell. I am having a hard time trying to explain wha I mean so I try to use an example. For example i have the number .93 in cell B3. I want the number i cell C3 to depend on the number in B3. For example if the number i between .90 and 1 I want the number in C3 to be 4, if the number i between .80 and .90 I want the number in C3 to be 3, and so on. Th number in cell B3 does change, so I want the number in C3 to chang based on the change of B3. Any help is greatly appreciated -- slag01 --------------...

Find file and remove .csv extension
Hi, I'm tring to open a window, select a file with CSV extension, the file is coded to SelectedFile and then remove I want to remove the .CSV before renaming the file with the same name albeit with a .TXT extension. I've tried the code below for the inital test but it fails on the WorksheetFunction code. Am I on the right track? Thanks, Rob Sub macro1() Dim Filter, Caption, SelectedFile, DestinationFile As String Filter = "Text files (*.csv),*.csv" Caption = "Please Select a File " & TheUser SelectedFile = Application.GetOpenFilename(F...

Reports functionality
Anyone modify the Reports at all? I was not looking to write reports from scratch (unless I had to) - I wanted to use the existing reports, but customize. For example, I would like to see the Account Details Report, categorized/grouped by Territory - and that doesn't appear possible with the existing reports. Also, does anyone know for sure if Crystal Reports will be pulled out and replaced by the new SQL Server Reporting Services? I have no prior experience with Crystal, and would rather learn the technology that will be used long-term for CRM Reports... Thanks in advance. To custo...

Sorting an XML document.
I have a slightly different sorting question than has been proposed before. My docuement looks like: <Records> <Record> <Sequence>5</Sequence> <Name>E</Name> </Record> <Record> <Sequence>1</Sequence> <Name>A</Name> </Record> <Record> <Sequence>4</Sequence> <Name>D</Name> </Record> <Record> <Sequence>2</Sequence> <Name>B</Name> </Record> <Record> <Sequence>3</Sequence> &...

faq do not know my object
Hi, I write a class CSide, side.h and side.cpp is ok, compile ok. Now I want to use it. In my mfc SDI project, I declare a CSide myside in C*doc class, surly I put a line to include the head file of CSide. But when I try to use myside in constructor of C*doc, it seem to be it does not know myside. Why? Thanks. You will need to put something like: #include "side.h" In the header file for the object where you want to include your class. Then you can instantiate it either as a member or as a local object using something like: CSide m_MySide; Tom "fcvcnet" <f...

Outlook settings roaming profile
Hello, We use both outlook 2000 and 2003, with exchange 2003. I want to setup a romaing profile for outlook settings for my users, so that whicever PC they log in to will have same setting, and I don't have to manage PC by PC. Never created a romaing profile, and new to this. Can anyone help me with this with an example? Thanks for the help MC http://www.slipstick.com/exs/olroam.htm --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. After furious head scrat...

Null values in charts and how to override the goal seek functionality
Hi all, I am trying to chart data that contains null values, I want the null values to be represented as a gap or such. The chart series are dynamically created from code using a series formula. The chart needs to be editable as well as the underlying data. My attempts at displaying null data is slowly painting me into a corner. Issue 1: The series formula will not allow null values to be included in the selected cells. Any attempt to include a null value in the series range will give me a COMException. Workaround 1: Bind the series to an area on the sheet filled wi...

blank lines screwing up XMLDocument object
I have an XMLDocument object that is attempting to parse an xml document generated by a cold fusion page. The problem is that for some reason the cold fusion page is generating a number of carriage returns preceding the XML declaration. This is causing the following error: System.Xml.XmlException: The XML declaration is unexpected. Line 80, position 3. at System.Xml.XmlTextReader.ParseTag() at System.Xml.XmlTextReader.ParseRoot() at System.Xml.XmlTextReader.Read() at System.Xml.XmlValidatingReader.ReadWithCollectTextToken() at System.Xml.XmlValidatingReader.Read() at System.Xml.XmlLoa...