473,503 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing XML as XsltArgumentList, 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 3548
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 XPathNodeIterator to be able to work with it as with
nodeset in XSLT.
XPathNavigator is RTF in XSLT, XPathNodeIterator - 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.CreateNavigator();
XsltArgumentList args = new XsltArgumentList();
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.SelectSingleNode("/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!PLEASEtkachenko.com> wrote in message
news:%2****************@TK2MSFTNGP10.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 XPathNodeIterator to be able to work with it as with
nodeset in XSLT.
XPathNavigator is RTF in XSLT, XPathNodeIterator - 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.CreateNavigator();
XsltArgumentList args = new XsltArgumentList();
args.AddParam("properties", "", nav.Select("./*")); //changed this to no
namespace XPath

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

Thanks,

Tim

"Tim Menninger" <tm********@forensicsexplorers.com> wrote in message
news:%2****************@TK2MSFTNGP09.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.CreateNavigator();
XsltArgumentList args = new XsltArgumentList();
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.SelectSingleNode("/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!PLEASEtkachenko.com> wrote in message
news:%2****************@TK2MSFTNGP10.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 XPathNodeIterator to be able to work with it as with
nodeset in XSLT.
XPathNavigator is RTF in XSLT, XPathNodeIterator - 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.SelectSingleNode("/FE:Properties") does work.


You have to provide XmlNamespaceManager to Select method to define FE
prefix:

XPathExpression expr = nav.Compile("/FE:Properties");
XmlNamespaceManager mngr = new XmlNamespaceManager(nav.NameTable);
mngr.AddNamespace("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!PLEASEtkachenko.com> wrote in message
news:%2****************@tk2msftngp13.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.SelectSingleNode("/FE:Properties") does
work.
You have to provide XmlNamespaceManager to Select method to define FE
prefix:

XPathExpression expr = nav.Compile("/FE:Properties");
XmlNamespaceManager mngr = new XmlNamespaceManager(nav.NameTable);
mngr.AddNamespace("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
3077
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...
2
4013
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...
1
1941
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...
4
4779
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...
1
2802
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...
1
1623
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>...
2
2824
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...
7
2828
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...
1
1937
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 =...
0
7198
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,...
0
7449
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...
0
5570
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,...
1
4998
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...
0
4666
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...
0
3160
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...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
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...

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.