Sam Akiwumi
2004-03-05 14:52:55 UTC
Hi
I am trying to get the transform the following XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"
href="C:\Projects\kmc.co.uk\e-commerce\Rules Engine\XSL
Stylesheets\Nodeset.xsl"?>
<books>
<book author="Michael Howard">Writing Secure Code</book>
<book author="Michael Kay">XSLT Reference</book>
</books>
Using the following XSL
----------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://www.contoso.com">
<xsl:variable name="books"
select="document('file://C:\Projects\kmc.co.uk\e-commerce\Rules
Engine\XML\Untitled2.xml')"/>
<xsl:template match="/">
<authors>
<xsl:for-each select="msxsl:node-set($books)/books/book">
<author><xsl:value-of select="@author"/></author>
</xsl:for-each>
</authors>
</xsl:template>
</xsl:stylesheet>
---------------------------
I have created code in C# to do the transformation and I am using the
built-in XSLT Processor (implements the XSL Transformations (XSLT)
Version 1.0 recommendation).
Code
----------------------------
//Load the file to transform.
XPathDocument doc = new XPathDocument(xmlFile);
// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
//Load the stylesheet
XmlDocument xsl = new XmlDocument();
xsl.Load(stylesheet);
XslTransform xslt = new XslTransform();
xslt.Load(xsl, resolver, this.GetType().Assembly.Evidence);
//Create an XmlTextWriter which outputs to the console.
StreamWriter outputWriter = new StreamWriter("C:\\Temp\\result1.xml");
XmlTextWriter writer = new XmlTextWriter(outputWriter);
//Transform the file and send the output to the console.
xslt.Transform(doc, null, writer, resolver);
----------------------------------
When I run the code, I get the an exception (below) which says the
Function 'msxsl:node-set()' has failed.
EXCEPTION
-----------------
InnerEx=System.Xml.Xsl.XsltException: Cannot convert the operand to
'Result tree fragment'.
at System.Xml.Xsl.XsltFunctionImpl.ToNavigator(Object argument)
at System.Xml.Xsl.FuncNodeSet.Invoke(XsltContext xsltContext,
Object[] args,
XPathNavigator docContext)
at System.Xml.XPath.XsltFunction.InvokeFunction(XPathNavigator qy,
XPathNodeI
terator iterator)
-----------------
Any ideas why this is happening? tx
Sam
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
I am trying to get the transform the following XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"
href="C:\Projects\kmc.co.uk\e-commerce\Rules Engine\XSL
Stylesheets\Nodeset.xsl"?>
<books>
<book author="Michael Howard">Writing Secure Code</book>
<book author="Michael Kay">XSLT Reference</book>
</books>
Using the following XSL
----------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://www.contoso.com">
<xsl:variable name="books"
select="document('file://C:\Projects\kmc.co.uk\e-commerce\Rules
Engine\XML\Untitled2.xml')"/>
<xsl:template match="/">
<authors>
<xsl:for-each select="msxsl:node-set($books)/books/book">
<author><xsl:value-of select="@author"/></author>
</xsl:for-each>
</authors>
</xsl:template>
</xsl:stylesheet>
---------------------------
I have created code in C# to do the transformation and I am using the
built-in XSLT Processor (implements the XSL Transformations (XSLT)
Version 1.0 recommendation).
Code
----------------------------
//Load the file to transform.
XPathDocument doc = new XPathDocument(xmlFile);
// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
//Load the stylesheet
XmlDocument xsl = new XmlDocument();
xsl.Load(stylesheet);
XslTransform xslt = new XslTransform();
xslt.Load(xsl, resolver, this.GetType().Assembly.Evidence);
//Create an XmlTextWriter which outputs to the console.
StreamWriter outputWriter = new StreamWriter("C:\\Temp\\result1.xml");
XmlTextWriter writer = new XmlTextWriter(outputWriter);
//Transform the file and send the output to the console.
xslt.Transform(doc, null, writer, resolver);
----------------------------------
When I run the code, I get the an exception (below) which says the
Function 'msxsl:node-set()' has failed.
EXCEPTION
-----------------
InnerEx=System.Xml.Xsl.XsltException: Cannot convert the operand to
'Result tree fragment'.
at System.Xml.Xsl.XsltFunctionImpl.ToNavigator(Object argument)
at System.Xml.Xsl.FuncNodeSet.Invoke(XsltContext xsltContext,
Object[] args,
XPathNavigator docContext)
at System.Xml.XPath.XsltFunction.InvokeFunction(XPathNavigator qy,
XPathNodeI
terator iterator)
-----------------
Any ideas why this is happening? tx
Sam
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!