473,569 Members | 2,542 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing XML as XsltArgumentLis t, can't select children

I have seen the postings about passing XML into an XSL transformation. The
problem is that I cannot use any XPath navigation in the XSL that won't
generate an error. If I use <xsl:copy-of select="$var"/> then the XML is
output into the html page but this <xsl:copy-of select="$var/NS:Child"/>,
and all other XPath navigation, fails with the error that 'The expression
passed to this method should result in a NodeSet'. The real goal is to use
xsl:for-each to navigate over all $var's children but can't get it to work.

I have seen the samples and they all show I should be able to do this. The
only difference is that the samples never use namespaces and I have a
namspace on my xml.

Tim
Nov 12 '05 #1
5 3553
Tim Menninger wrote:
I have seen the postings about passing XML into an XSL transformation. The
problem is that I cannot use any XPath navigation in the XSL that won't
generate an error. If I use <xsl:copy-of select="$var"/> then the XML is
output into the html page but this <xsl:copy-of select="$var/NS:Child"/>,
and all other XPath navigation, fails with the error that 'The expression
passed to this method should result in a NodeSet'. The real goal is to use
xsl:for-each to navigate over all $var's children but can't get it to work.


You must be passing XPathNavigator to XSLT?
You have to pass XPathNodeIterat or to be able to work with it as with
nodeset in XSLT.
XPathNavigator is RTF in XSLT, XPathNodeIterat or - nodeset.
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #2
Oleg,

Thanks, I did try this but since my XML has a namespace I could not figure
out how to set the XsltContext for the query. Below is the code I am using.

//props is XmlNode
XPathNavigator nav = props.CreateNav igator();
XsltArgumentLis t args = new XsltArgumentLis t();
args.AddParam(" properties", "", nav.Select("/FE:Properties") );

The .Select() method throws an exception 'Namespace Manager or XsltContext
needed. This query has a prefix,
variable, or user-defined function'. The XmlNode's XmlDocument has the
correct context set, so props.SelectSin gleNode("/FE:Properties") does work.

I have tried to use the second param in AddParam but I do not think this
does what I need.

Tim
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Tim Menninger wrote:
I have seen the postings about passing XML into an XSL transformation. The problem is that I cannot use any XPath navigation in the XSL that won't
generate an error. If I use <xsl:copy-of select="$var"/> then the XML is
output into the html page but this <xsl:copy-of select="$var/NS:Child"/>, and all other XPath navigation, fails with the error that 'The expression passed to this method should result in a NodeSet'. The real goal is to use xsl:for-each to navigate over all $var's children but can't get it to
work.
You must be passing XPathNavigator to XSLT?
You have to pass XPathNodeIterat or to be able to work with it as with
nodeset in XSLT.
XPathNavigator is RTF in XSLT, XPathNodeIterat or - nodeset.
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com

Nov 12 '05 #3
Oleg thanks for the quick response,

I got it working but not really the way I wanted. If you could answer the
namespace question that would be great. This is what I changed

XPathNavigator nav = props.CreateNav igator();
XsltArgumentLis t args = new XsltArgumentLis t();
args.AddParam(" properties", "", nav.Select("./*")); //changed this to no
namespace XPath

Then used <xsl:for-each select="$proper ties"> to output rows

Thanks,

Tim

"Tim Menninger" <tm********@for ensicsexplorers .com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Oleg,

Thanks, I did try this but since my XML has a namespace I could not figure
out how to set the XsltContext for the query. Below is the code I am using.
//props is XmlNode
XPathNavigator nav = props.CreateNav igator();
XsltArgumentLis t args = new XsltArgumentLis t();
args.AddParam(" properties", "", nav.Select("/FE:Properties") );

The .Select() method throws an exception 'Namespace Manager or XsltContext
needed. This query has a prefix,
variable, or user-defined function'. The XmlNode's XmlDocument has the
correct context set, so props.SelectSin gleNode("/FE:Properties") does work.
I have tried to use the second param in AddParam but I do not think this
does what I need.

Tim
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Tim Menninger wrote:
I have seen the postings about passing XML into an XSL transformation. The problem is that I cannot use any XPath navigation in the XSL that won't generate an error. If I use <xsl:copy-of select="$var"/> then the XML is output into the html page but this <xsl:copy-of select="$var/NS:Child"/>, and all other XPath navigation, fails with the error that 'The expression passed to this method should result in a NodeSet'. The real goal is to use xsl:for-each to navigate over all $var's children but can't get it to

work.

You must be passing XPathNavigator to XSLT?
You have to pass XPathNodeIterat or to be able to work with it as with
nodeset in XSLT.
XPathNavigator is RTF in XSLT, XPathNodeIterat or - nodeset.
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com


Nov 12 '05 #4
Tim Menninger wrote:
args.AddParam(" properties", "", nav.Select("/FE:Properties") );

The .Select() method throws an exception 'Namespace Manager or XsltContext
needed. This query has a prefix,
variable, or user-defined function'. The XmlNode's XmlDocument has the
correct context set, so props.SelectSin gleNode("/FE:Properties") does work.


You have to provide XmlNamespaceMan ager to Select method to define FE
prefix:

XPathExpression expr = nav.Compile("/FE:Properties") ;
XmlNamespaceMan ager mngr = new XmlNamespaceMan ager(nav.NameTa ble);
mngr.AddNamespa ce("FE","FE namespace URI goes here");
expr.SetContext (mngr);
args.AddParam(" properties", "", nav.Select(expr ));

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #5
Oleg,

Thanks, got it working. I had tried this but I was using the prop's
XmlDocument NameTable not the nav's NameTable this must have caused a
problem. I actually have a wrapper class around XmlDocument that manages my
namespaces so I don't have to create a namespace manager for each dom. I was
using my GetNsMgr() accessor to return the XmlDocuments namespace manage and
pass that to SetContext but that didn't work. When you recreate a namespace
manager it works.

Thanks,

Tim
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Tim Menninger wrote:
args.AddParam(" properties", "", nav.Select("/FE:Properties") );

The .Select() method throws an exception 'Namespace Manager or XsltContext needed. This query has a prefix,
variable, or user-defined function'. The XmlNode's XmlDocument has the
correct context set, so props.SelectSin gleNode("/FE:Properties") does
work.
You have to provide XmlNamespaceMan ager to Select method to define FE
prefix:

XPathExpression expr = nav.Compile("/FE:Properties") ;
XmlNamespaceMan ager mngr = new XmlNamespaceMan ager(nav.NameTa ble);
mngr.AddNamespa ce("FE","FE namespace URI goes here");
expr.SetContext (mngr);
args.AddParam(" properties", "", nav.Select(expr ));

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com

Nov 12 '05 #6

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

Similar topics

0
3084
by: Anders Borum | last post by:
Hello! I would like to request a new method on the XsltArgumentList class, allowing developers to check the presense of a key/value pair. If you try to add a key/value pair that has already been defined in the list, an exception is thrown. Rather than using the "GetParam" method, it would be usefull to have a method called ".Exists"...
2
4025
by: Craig Petrie | last post by:
The following transformation puzzles me when trying to transform XML to XML. I get an exception "THE EXPRESSION PASSED TO THIS METHOD SHOULD RESULT IN A NODESET" at the last line "xmlDoc.Load(xr)" when I run the code. I previously tried it all without a parameter and hard-coded the value into the 'apply-templates' statement and the...
1
1952
by: NicoAgenci | last post by:
Hello, I have a page in .net (DEFAULT.ASPX), i load a XmlDocument, and a XslTransform to Add a XsltArgumentList (with the param : urlPage), and send all to a <asp:xml> in the page. The <asp:xml> is good with xml and xsl, but the param is not fill with the value ? Do you have a solution ??? Thanx
4
4785
by: Paul | last post by:
Hi all. This one is really getting to me now, I'm using the <asp:xml web server control and I'm trying to use the XsltArgument list to add a custom class so that I can do some formatting in the XSL style sheet. however each time it complains that the prefix "util" could not be found, any ideas???????? bloody thing is driving me mad code...
1
2808
by: DagoFlores | last post by:
Hello, I am trying to pass a parameter through C# using a XsltArgumentList class to a xsl:param element, but I dont know if it is possible to do. And also I am trying to get the count of this node too, that has as name the value of the parameter. The "DateElementName" value is the name of a selected node that I want to know the count on...
1
1635
by: chris yoker via DotNetMonster.com | last post by:
hiya, I add new nodes to an xmlDoc. I want to add "innerText" to every newly-created node. current XML file <code> <rows> <row> <PRODUCT-TYPE>bike</PRODUCT-TYPE> <PRODUCT-DATE>01/01/2004</PRODUCT-DATE>
2
2829
by: Oleksandr Brovko | last post by:
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...
7
2839
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID);...
1
1943
by: Sam | last post by:
I am working with .Net 2.0. I found a 2002 posting with this sample code of how to send a node-set into a XSLT transformation: string xml = @"<foo><bar>The Test</bar></foo>"; string xsl = @"<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""1.0""> <xsl:param name=""param1""/> <xsl:template match=""/""> bar...
0
7700
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...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7676
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7974
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...
1
5513
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
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...
0
3653
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...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
938
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...

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.