Hello, I found solution for subj related to the Visual Studio XSLT processor:
public class XsltListFilesExtension
{
public XPathNodeIterator ListFiles(string directoryPath)
{
XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateElement("files"));
DirectoryInfo di = new DirectoryInfo(directoryPath);
foreach (FileInfo fi in di.GetFiles())
{
XmlElement file = doc.CreateElement("file");
file.SetAttribute("name", fi.Name);
file.SetAttribute("size", fi.Length.ToString());
doc.DocumentElement.AppendChild(file);
}
return doc.DocumentElement.CreateNavigator().SelectChildren("file", "");
}
}
class Program
{
static void Main(string[] args)
{
XslTransform t = new XslTransform();
t.Load("transform.xslt");
XsltArgumentList xsltArgs = new XsltArgumentList();
xsltArgs.AddExtensionObject("urn:list-files-extension", new XsltListFilesExtension());
XPathDocument input = new XPathDocument("input.xml");
using (FileStream output = new FileStream("output.txt", FileMode.Create))
{
t.Transform(input, xsltArgs, output);
}
}
}
The XSLT trasform.xslt:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
xmlns:lfe="urn:list-files-extension">
<xsl:output method="text" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="lfe:ListFiles('D:\temp')">
<xsl:value-of select="@name"/>
<xsl:text> - </xsl:text>
<xsl:value-of select="@size"/>
<xsl:text>bytes
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Can I to do solution like this but for common scope, for instance: the same xslt file can execute using java xslt processor, C# and etc. ? Thanks.