473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Did I miss something here ?

Ok guys, I could bang my head on the laptop, cause I dont
get this to work. The scanrio: I am tryting to pass an
parameter with the help of XslTransform to the xsl file.
But whenever I run the code, I got the error:

System.Xml.XPath.XPathException: Expression must evaluate
to a node-set.

Maybe somebody can help me out here:

my xml file:

<?xml version="1.0" encoding="utf-8"?>
<CategoryList>
<Category>
<MainCategory>1</MainCategory>
<Description>This is a list my XML
articles.</Description>
<Active>true</Active>
</Category>
<Category>
<MainCategory>2</MainCategory>
<Description>This is a list my XML
articles.</Description>
<Active>true</Active>
</Category>
<Category>
<MainCategory>3</MainCategory>
<Description>This is a list my XML
articles.</Description>
<Active>true</Active>
</Category>
</CategoryList>

my xsl file:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="strXPath" />

<xsl:template match="/">
<xsl:apply-templates select="$strXPath" />
</xsl:template>

<xsl:template match="Category">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>

my code:

XmlDocument xmlDoc= new XmlDocument();
xmlDoc.Load(Server.MapPath("categories.xml"));

XslTransform xslt = new XslTransform();
xslt.Load(Server.MapPath("categories.xslt"));

XPathNavigator nav = xmlDoc.CreateNavigator();

XsltArgumentList arguments = new XsltArgumentList();
arguments.AddParam("strXPath", "", nav.Select
("//Category/MainCategory"));

MemoryStream ms = new MemoryStream();
xslt.Transform( nav, null, ms, null);
ms.Seek( 0, SeekOrigin.Begin );

StreamReader sr = new StreamReader(ms);

//Print out the result
Response.Write(sr.ReadToEnd());

Thanks, Sonu
Nov 12 '05 #1
1 1917
I solved the problem. The problem was that I forgot to
pass the parameters.

here is the line:
xslt.Transform( nav, null, ms, null);

This should be changed to:
xslt.Transform( nav, arguments, ms, null);

Sonu
-----Original Message-----
Ok guys, I could bang my head on the laptop, cause I dont
get this to work. The scanrio: I am tryting to pass an
parameter with the help of XslTransform to the xsl file.
But whenever I run the code, I got the error:

System.Xml.XPath.XPathException: Expression must evaluate
to a node-set.

Maybe somebody can help me out here:

my xml file:

<?xml version="1.0" encoding="utf-8"?>
<CategoryList>
<Category>
<MainCategory>1</MainCategory>
<Description>This is a list my XML
articles.</Description>
<Active>true</Active>
</Category>
<Category>
<MainCategory>2</MainCategory>
<Description>This is a list my XML
articles.</Description>
<Active>true</Active>
</Category>
<Category>
<MainCategory>3</MainCategory>
<Description>This is a list my XML
articles.</Description>
<Active>true</Active>
</Category>
</CategoryList>

my xsl file:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="strXPath" />

<xsl:template match="/">
<xsl:apply-templates select="$strXPath" />
</xsl:template>

<xsl:template match="Category">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>

my code:

XmlDocument xmlDoc= new XmlDocument();
xmlDoc.Load(Server.MapPath("categories.xml"));

XslTransform xslt = new XslTransform();
xslt.Load(Server.MapPath("categories.xslt"));

XPathNavigator nav = xmlDoc.CreateNavigator();

XsltArgumentList arguments = new XsltArgumentList();
arguments.AddParam("strXPath", "", nav.Select
("//Category/MainCategory"));

MemoryStream ms = new MemoryStream();
xslt.Transform( nav, null, ms, null);
ms.Seek( 0, SeekOrigin.Begin );

StreamReader sr = new StreamReader(ms);

//Print out the result
Response.Write(sr.ReadToEnd());

Thanks, Sonu
.

Nov 12 '05 #2

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

Similar topics

1
by: kmounkhaty | last post by:
Hi Guru, My profiler trace does not display SP:CACHEMISS event, even thought I drop store proc, clear both data cache and buffer cache but still does not work. Every thing works fine like:...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
28
by: Useful Info | last post by:
Like on 9/11, the Federal Government apparently WANTED people to die at the hands of Cho at VA Tech, because they told campus police not to pursue Cho after the double homicide occurred. Story...
8
by: anukedari | last post by:
Hi, Could any boby please help to get the answers for the following questions: Is Apache always sends "X-Cache:MISS" header even when caching is off (disable)? or Can we say that cache...
0
by: manikandan | last post by:
dont miss it just open dont miss it just open dont miss it just open #############################
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...
0
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...

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.