469,647 Members | 1,803 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

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 3412
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Craig Petrie | last post: by
1 post views Thread by DagoFlores | last post: by
1 post views Thread by chris yoker via DotNetMonster.com | last post: by
7 posts views Thread by Harolds | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.