loop using <xsl:for-each> and external javascript function

Hi,

I have an xsl as below.  I am trying to loop using <xsl:for-each> and
in the select attribute of <xsl:for-each> i am getting the nodeset
from the external javascript function in the <CDATA> section.

This code works fine with MSXML4.0 parser.  
When I try to use .Net, it gives me error saying " The expression
passed to this method should result in a NodeSet."

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:local1="http://csc.com/mynamespace"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:variable name="vRoot" select="/"/>
<xsl:template match="customers">
<html>
<head>
<title>Create An HTML file With An XSL Transformation</title>

</head>
<body>
<xsl:for-each select="local1:selectNodes($vRoot,'customer')">
	<xsl:value-of select="."/>  hello
</xsl:for-each>
</body>

</html>
</xsl:template>
	<msxsl:script language="JScript" implements-prefix="local1"><![CDATA[
		  function selectNodes(contextNodeList,path)
		  {

			// Added code to return current node if path string is empty
			  if (path == "")
			    {
			     path = ".";
			    }
			return contextNodeList.Current.Select(path);

		  }
		]]></msxsl:script>

</xsl:stylesheet>

----------------------  xml file ---------------
<customers>
   <customer abc1="hiher" xyz="xyz">
      <name>John Smith</name>
      <address>123 Elm St.</address>
      <phone>(123) 456-7890</phone>
   </customer>
   <customer>
      <name>Mary Jones</name>
      <address>456 Oak Ave.</address>
      <phone>(156) 789-0123</phone>
   </customer>
</customers>



If I change the xsl:for-each as below then it gives me the desired
result
<xsl:variable name="temp"
select="local1:selectNodes($vRoot,'customer')"/>
<xsl:for-each select="$temp">
	<xsl:value-of select="."/>  hello
</xsl:for-each>


I am not sure why this happens. Is there anything that I am missing ?

Appreciate your help

Thanks,
Jignesh
0
6/17/2004 6:41:38 AM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
487 Views

Similar Articles

[PageSpeed] 22

jd wrote:

> I have an xsl as below.  I am trying to loop using <xsl:for-each> and
> in the select attribute of <xsl:for-each> i am getting the nodeset
> from the external javascript function in the <CDATA> section.
> 
> This code works fine with MSXML4.0 parser.  

Well, it can't work with MSXML because of Current property and Select() 
method, they are .NET-specific ones.

> When I try to use .Net, it gives me error saying " The expression
> passed to this method should result in a NodeSet."

Looks like that has something to do with JScript.NET. The same extension 
but written in C# works just fine:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:local1="http://csc.com/mynamespace"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:variable name="vRoot" select="/"/>
<xsl:template match="customers">
<html>
<head>
<title>Create An HTML file With An XSL Transformation</title>

</head>
<body>
<xsl:for-each select="local1:selectNodes($vRoot, 'customer')">
	<xsl:value-of select="."/>  hello
</xsl:for-each>
</body>

</html>
</xsl:template>
	<msxsl:script language="C#" implements-prefix="local1"><![CDATA[
		  XPathNodeIterator selectNodes(XPathNodeIterator contextNodeList, 
string path)
		  {			
			// Added code to return current node if path string is empty
			  if (path == "")
			    {
			     path = ".";
			    }
			
			return contextNodeList.Current.Select(path);

		  }
		]]></msxsl:script>

</xsl:stylesheet>

-- 
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
0
Oleg
6/17/2004 8:40:23 AM
Reply:

Similar Artilces:

KB976098 gets into eternal update loop
I use Windows 7, 64 bit version. Update KB976098 gets into an eternal update loop every time. It never finishes, not even after a full night waiting. If I then press sleep or hybernate, the system continues updating when I restart again and I cannot do anything else but wait. It displays the message "Installing update 1 of 1" and nothing else happens. If I perform a hard reset by pressing my start key for 5 seconds the system finally stops, but when I then restart I get the error message that the system was shut down wrongly. To be able to proceed at all I then have to...

format-number function & .NET
When I do a transform with a stylesheet containing the function format-number($varname,'#,##0.00') from XSLerator (which uses MSXML) I get the result I expect, a decimal number rounded to 2 places. When I load the stylesheet & do the transform from my VB.NET or C# code however (i.e. using system.xml etc) I always get NaN returned. I don't know why, it took me ages to work it out but the fix is to cast the first parameter in the function to number, i.e. format-number(number($varname),'#,##0.00'), then I get what I expect. Anyone know why I am getting this behaviour?...

Range referencing in VLOOKUP function, string concatenate?
I am attempting to perform a vlookup in an array, located among a group of 21 other arrays. So, each array has a name beside it, but the arrays all contain Similar, and sometimes identical data. I first use a MATCH function to find the name and its location on the worksheet containing all the arrays. I now desire to embed the match function in my vlookup along these lines... =vlookup(AJ4,Jobs!"B"&MATCH(AJ3,Jobs!A2:A2123)+2:Jobs!"W"&MATCH (AJ3,Jobs!A2:A2123)+100) where AJ3 contains the name i am initially looking up, and AJ4 contains the value I wish to find in ...

Is there a way to set tranform timeout to avoid dead loop? thanks
...

Can you create a performance dashboard using Excel?
I'd like to create performance dashboards for organizations. These would consist of multiple charts on one page reflecting current and year to date performance for key measures. Is there an Excel template that does this? ...

TreeView and research function
Hi, I'm using a TreeView to display several information to user. 1. I would like to know if exist a method to hide some of TreeView's rows ? 2. The same for showing all rows ? 3. Does a search function exist to research a "string" part through all cells of TreeView ? thanks, Maileen Maileen <nospan@email.com> wrote in message news:<OQiWZxDMEHA.3216@tk2msftngp13.phx.gbl>... > Hi, > > I'm using a TreeView to display several information to user. > 1. I would like to know if exist a method to hide some of TreeView's rows ? > 2. The same fo...

How to use CSocket & Serialize in multithread network program?
Hi, all I'm writing a multithread program to transfer object data, I want to use CSocket & CSocketFile to serialize objects over network. On the server, I start a listening socket in main thread, when OnAccept() occurs, the main thread will create a sub thread that with a CSocket member, and the CSocket member will be accepted in main thread. I think the sub thread will take charge with the serialization of data before, but now it seems that the serialize code is run in the main thread, when serializing, the main thread can't accept new connection. How to use CSocket & ...

CRM reports Externally
This is regarding issue we are having trying to access CRM reports Externally -Clicking on Reports in CRM web externally takes you to the list of available - reports fine, but when you try to 'Run report', it returns a 401. -If URL is pointed directly to the Reports URL (http://crm.domainname.com.au:5555/reports) the reports are Available and user can ‘Run Report’ with "An error has occurred during report processing. (rsProcessingAborted) Cannot create a connection to data source 'CRM'. (rsErrorOpeningConnection) For more information about this error navigate ...

Excel crashes when writing formula referencing to external workbook in freeze frame
This is a problem in Excel 2003. Not sure it exists in later version. Scenerio: In sheet1 of book1, the frame was frozen (freeze frame) to see the top rows. In sheet1 of book2, there is no freeze frame. Write any formula in sheet1, book1 that references sheet1 of book2 will cause Excel to crash. Work around: Un-freeze frame in sheet1 of book1 before writing the referencing formula. Or, freeze a frame in sheet1 of book2 before writing the formula in book1. The key is, both sheets (the originating sheet and the destination sheet in the external book) must be synchronized ...

Disable the forwarding function (RMS?)
Hi, I want to preserve the confidentiality of an email so that the receipient (internal or external) of the email won't be able to forward the email to others. Is it doable? The Microsoft Right Management Service + Liquid Machines seem serving the purpose, but the deployment doesn't look straight forward. Anyone has the experience to share? Any alternatives? I know Lotus Notes has the similar function out of the box. Does MS Outlook provide this too? Thanks RMS can definitely add that capability to Outlook, which has nothing = like that built in. People I've talked to who...

Run-time error'1004 using PasteSpecial
Great Gurus of VBA, I use the following Code to copy information from dozens of identica worksheets to a master log. The information is transfered from on worksheet at at time to the master log. The code has been working fin until I added protection to the Master Log and so had to add code o the sheets to unlock the Master Log prior to pasting the data and the re-locking the master Log. Below is my code. Sorry for all the notes but I still learning. The code stops on the line: Selection.PasteSpecial Paste:xlPlasteValues......................... With the following Error: Run-time error ...

Using Outlook'98 to manage files performs illegal operation
I setup the outlook bar w/ shortcuts to different folders (local & network) so that I could use it instead of windows explorer. The first time I set this up, it worked fine for a couple of days, and now all I get is illegal operations when I click on one of the short cuts. OUTLOOK caused an invalid page fault in module KERNEL32.DLL at 015f:bff9d709. Any suggestions? ezroller ...

use "from" instead of "reply to" address when replying
When replying to a message that has a "reply to" field defined: is it possible to reply by sending a message to the address specified in the "from" field instead of the address defined in the "reply to" field? (in outlook 2002) Thanks Philippe By typing it yourself. Note that the sender defines the reply to field for a reason. -- Roady [MVP] www.sparnaaij.net Microsoft Office and Microsoft Office related News Also Outlook FAQ, How To's, Downloads and more... Tip of the month: -Create your own fully customized Toolbar Subscribe to the newsletter to rece...

Help needed with sum function
Hello, Hopefully i can have a few questions answered all at once here. 1) Is the sum function within excel limited to approximately 30 cells ? e.g. when I sum the cells =sum(c14,c22,c30,c38,c46��� it seems to stop after I get to about 30 cells. 2) Is there a difference in summing them like that or like this =sum(c14+c22+c30+���. 3) is there a quicker way to sum cells when they are each a constant number apart, like the above scenario where each cell number I want to sum increases by 8 each time ? I have about 52 cells to sum (one for each week of the year) and I am thinkin...

How do I use Names in the Header
I am trying to automate my header, but do not want to use the limited selection. I want to Enter some data into a NAMED range, OR the File Propoerties Fields, then have them show up in my header! ...

USING EDIT FIND to locate cell references
If I put various cell references inside a formula, is there an easy wa to find the reference without going into each and every cell. Fo example if cell C6 is "=IF(ISERROR(T9/Q9),"",T9/Q9)" and I want to fin all references to T9 can I somehow convert cell C6 to be say the text o the formula and then do a Edit Find on all cells in the worksheet? I hope that i explained myself. Thanks -- Ron Wilso ----------------------------------------------------------------------- Ron Wilson's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2729 View this thre...

Using language DLLs for strings ONLY
(Cross-posted to ms.public.windowsce.embedded, sorry to people who read both groups) I've created a per-language DLL with some string resources and when my app loads I'm trying to load the module and get the string resources from there instead. The test code that does it is simply: HINSTANCE hRes = NULL; hRes= LoadLibrary(_T("res0C0A.dll")); if (hRes) AfxSetResourceHandle(hRes); My problem is that after setting the resource handle to the other DLL, the app tries to load ALL resources from that DLL (which of course fails). It seems my options are either to c...

Why does Outlook not start when I use the shortcut in Start-up pan
Hello, When I close Outlook (when installing a new program f.i.), I can not start Outlook again from the shortcut in the start-up panel. The message appearing is " this operation failed". I have to restart my computer to solve the problem. This does not happen with the other shorcuts for Word, Excell and Internet. The same problem when I try to start from C\Program Files\Office\Office 11\Outlook. exe. Thanks for any possible help. Best regards. -- Jacques - Belgium "Jacques" <Jacques@discussions.microsoft.com> wrote in message news:4A105EF0-8048-47...

Translating function names
OK, so I have Excel in Spanish and I want to use this: http://www.exceltip.com/st/How_to_extract_a_file_name_from_a_path_in_Microsoft_Excel/366.html Is there any way to automatically translate the function names? -- dziw ------------------------------------------------------------------------ dziw's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=10422 View this thread: http://www.excelforum.com/showthread.php?threadid=383378 Hi Dziw, See KeepItCool's TranslatIT addin at: http://members.chello.nl/keepitcool/download.html --- Regards, Norman ...

Best way to search content in cases (Using CRM as Hepdesk Solution
I use CRM to manage my helpdesk. CRM receives incoming emails from my customers and creates "Cases" Each Case History is made up of all the emails and other activities associated with a case. Is there an easy way to search "All Cases" for text strings that may be contained in any of the activities or emails or resolution descriptions associated with a case? TIA Joe I figured it out:: --- for the benefit of others "Advanced Find" has a system view that will search "All Activities" If you search the "Description" it searches all te...

Loop to cleanup data
Hi, I have a spreadsheet that is a dump from a survey. Problem is, sometimes the dump puts data that should be in one row on two. I need to write a macro that will see there is a second row, and if there is, move it up one row. It's easy to identify which rows need to get moved, because the data starts in column D rather than A. Problem is, I'm not good with syntax as you can see. I need the column name to stay the same, but increment which row I am on. I want i and p to keep track of that so that when I say Ci it equals C3 if in row 3, C4 if in row 4, etc. Excel reads it though as co...

Multiple Reports to use only 1 Query
I am working on Financial Portfolio Reports. I have 3 reports. All Idendtical except for "Sorting and Grouping". Just different names to the report. Each is sorted differetly. ( by Par, by Ticker, and by Pct Owned) They all use the same query which has a "parameter" to choose the portfolio ID. The singular reports are selected on a switchboard menu with an event click code. I would like to use the query only once and print the 3 reports with one event click and not have it request the parameter over again. My code is included: Private Sub cmdSummaryTck_Click() On ...

Redirecting all e-mail from one external user (or domain) to an SBS (2003) user
Hello - this might seem a silly question, I hope not. I have a client who wishes to redirect all e-mail coming from an external user (example: fred@xyz.com), to a local user (wilma@companyname.com) I can block the e-mail from either the specific user or the domain, with or without an archive, in System Manager > Message Delivery properties, but cannot work out how to simply forward the specific e-mails. Any assistance greatly appreciated, Thanks, Ashley ...

Insert Functions
Hello, I need to insert the current time and date into excel when a barcode is scanned from an ID card. It requires the [ "ctrl" + "shift" + ";" ] for which I can't find an ansii code for the latter or how to input the combination.. Any ideas how I can put this into the code so it will output to excel when the card is scanned. Also, it would be nice at the end of the code to get the focus to go to the next row, first column after a scan, to be ready for the next card. Any help is greatly appreciated. David A. Powell Hi in VBA why not use something...

Using cell value in range reference
I have a value of 20 in cell A1, how can I use this value in a formula. E.g. COUNTA("D11:D" & A1) - (I feel it should be similar to this ) Sandy =COUNTA(INDIRECT("D11:D"&a1)) -- Don Guillett Microsoft MVP Excel SalesAid Software dguillett1@austin.rr.com "Sandy" <sandy_stephen@DELETEhotmail.com> wrote in message news:4011B2E9-7F93-44E8-A3DF-96746B31C7FD@microsoft.com... >I have a value of 20 in cell A1, how can I use this value in a formula. > > E.g. COUNTA("D11:D" & A1) - (I feel it should be similar to this ) > > ...