Using Xpath over return value of an XSLT extension method?

There are two things to note : It is much more natural to apply the transformation to the result of invoking the method GetResultTable() than to get its result via an extension function As written the GetResultTable() method doesn't return any node at all: in the statement return doc.CreateNavigator(). Select("root") the Select() method doesn't select anything as there is no root element in doc The element named Root isn't selected, because XML and XPath are case-sensitive Another observation is that it isn't necessary at all to use xsl:for-each within an XSLT transformation this is considered not a good practice in most cases Having said that, here is the complete code for what this question asks for : namespace TestXml { using System; using System. Data; using System.IO; using System.

Xml; using System.Xml. XPath; using System.Xml. Xsl; class Program { static void Main(string args) { CustomObj co = new CustomObj(); XPathNodeIterator xpni = co.GetResultTable(); XslCompiledTransform xslt = new XslCompiledTransform(true); xslt.

Load(@"..\..\My. Xslt"); XsltArgumentList xargs = new XsltArgumentList(); xargs. AddExtensionObject("my:extension", co); XmlDocument fakeDoc = new XmlDocument(); fakeDoc.

LoadXml(""); StringWriter sw = new StringWriter(); xslt. Transform(fakeDoc.CreateNavigator(), xargs, sw); string result = sw.ToString(); Console. Write(result); } } public class CustomObj { //function that gets called from XSLT public XPathNodeIterator GetResultTable() { DataTable table = new DataTable("Table1"); table.Columns.

Add("SourceCity"); table.Columns. Add("DestinationCity"); table.Columns. Add("Fare"); table.Rows.

Add(new object { "New York", "Las Vegas", "100" }); table.Rows. Add(new object { "New York", "London", "200" }); table.Rows. Add(new object { "New York", "New Delhi", "250" }); StringWriter writer = new StringWriter(); table.

WriteXml(writer); XmlDocument doc = new XmlDocument(); XmlElement root = doc. CreateElement("Root"); root. InnerXml = writer.ToString(); doc.

AppendChild(root); return doc.CreateNavigator(). Select("Root"); } } } and the file My. Xslt : xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="my:extension" exclude-result-prefixes="my"> Source Destination Fare Source Destination Fare New York Las Vegas 100 New York London 200 New York New Delhi 250.

There are two things to note: It is much more natural to apply the transformation to the result of invoking the method GetResultTable() than to get its result via an extension function. As written the GetResultTable() method doesn't return any node at all: in the statement -- return doc.CreateNavigator(). Select("root"); the Select() method doesn't select anything as there is no root element in doc.

The element named Root isn't selected, because XML and XPath are case-sensitive. Another observation is that it isn't necessary at all to use xsl:for-each within an XSLT transformation -- this is considered not a good practice in most cases. Having said that, here is the complete code for what this question asks for: namespace TestXml { using System; using System.

Data; using System. IO; using System. Xml; using System.Xml.

XPath; using System.Xml. Xsl; class Program { static void Main(string args) { CustomObj co = new CustomObj(); XPathNodeIterator xpni = co.GetResultTable(); XslCompiledTransform xslt = new XslCompiledTransform(true); xslt. Load(@"..\..\My.

Xslt"); XsltArgumentList xargs = new XsltArgumentList(); xargs. AddExtensionObject("my:extension", co); XmlDocument fakeDoc = new XmlDocument(); fakeDoc. LoadXml(""); StringWriter sw = new StringWriter(); xslt.

Transform(fakeDoc.CreateNavigator(), xargs, sw); string result = sw.ToString(); Console. Write(result); } } public class CustomObj { //function that gets called from XSLT public XPathNodeIterator GetResultTable() { DataTable table = new DataTable("Table1"); table.Columns. Add("SourceCity"); table.Columns.

Add("DestinationCity"); table.Columns. Add("Fare"); table.Rows. Add(new object { "New York", "Las Vegas", "100" }); table.Rows.

Add(new object { "New York", "London", "200" }); table.Rows. Add(new object { "New York", "New Delhi", "250" }); StringWriter writer = new StringWriter(); table. WriteXml(writer); XmlDocument doc = new XmlDocument(); XmlElement root = doc.

CreateElement("Root"); root. InnerXml = writer.ToString(); doc. AppendChild(root); return doc.CreateNavigator().

Select("Root"); } } } and the file My. Xslt: Source Destination Fare When the application is executed, the wanted, correct result is produced: Source Destination Fare New York Las Vegas 100 New York London 200 New York New Delhi 250.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions