473,656 Members | 2,819 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 3570
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
3095
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" available on the XsltArgumentList. I think this allows for cleaner and more readable code. Or, perhaps...
2
4027
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 tranform produced the result that I expected but when I inset the parameter I get the exception.
1
1958
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
4799
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 snippet:
1
2812
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 the xml file. Any ideas? Thank you.
1
1648
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
2834
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 document through the document function and CustomXmlResolver now we pass $externalDoc/XML node set to...
7
2852
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); xmlItems.TransformArgumentList = xsltArgList;
1
1967
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 element from param1 value:
0
8382
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
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8600
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
7311
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
5629
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
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
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.