介绍。NET框架提供了{A1的} 这是一个XSLT处理器1.0。然而,这并不意味着我们不能正常工作。NET中使用XSLT 2.0。这篇文章是谁想要的乡亲XSLT 2.0中使用。NET中。
XSLT 2.0是比XSLT 1.0富裕。事实上,下面的XSLT 2.0中的某些功能。 正则表达式的当前日期,时间和日期分组XSL的多种功能:???驼峰规则的字符串的字符串比较标记化()和火柴()函数返回属性的基本处理器下比赛
{A2的所有功能和规格描述}。
{A3的。 有开源和也闭源的商业版本。Java和。NET版本存在。在本教程中,我们将使用撒克逊。NET的API来说明如何XSLT处理performed.Using的,codeInput
XML文件波纹管包含了一些城市的名单,他们的国家和人口数。
所需的输出<?xml version="1.0" encoding="utf-8"?>
<cities>
<city name="Milano" country="Italia" pop="1307495" />
<city name="Paris" country="France" pop="2220140" />
<city name="Bordeaux" country="France" pop="719489" />
<city name="M眉nchen" country="Deutschland" pop="1260391" />
<city name="Lyon" country="France" pop="474946" />
<city name="Venezia" country="Italia" pop="270801" />
<city name="Delft" country="Holland" pop="94512" />
<city name="Rotterdam" country="Holland" pop="607460" />
</cities>
产生
; 2011年12月22日23时42分27秒
0;
位置
60; 国家 城市列表
0; 人口
;
160;
; 1
法国
; 巴黎,里昂,波尔多
; 3.414575E6 &
#160;
60; 2 意大利
米兰,威尼斯
1.578296E6 &
#160;
0; 3
; 德国
; 慕尼黑 1.260391E6
160;
0;4 荷兰
160; 代尔夫特,鹿特丹
60; 701972XSLT处理
我们将XSLT转换成HTML报告包含这个XML文件责令人口数的国家名单和每个国家的城市名单分组。
在下面的XSLT,我使用xsl:以小组,由国家城市,每个组的发言。这是可能成立,XSLT 1.0中使用xsl:关键,但它将会更加复杂。
此外,你会发现,我用电流DATETIME()函数为了检索当前日期为了在时间和格式的DateTime()函数来格式化当前的日期和时间。{C}
下面的代码使用Saxon执行主要的XSLT处理。NET的API。
的其他选项是{A4纸},XSLT 2.0和XQuery 1.0的COM,可以用来与Windows的软件包。NET(通过COM互操作)。 namespace Saxon
{
internal class Program
{
private static void Main()
{
const string xmlFile = @"..\..\cities.xml";
const string xsltFile = @"..\..\cities.xslt";
const string outFile = @"..\..\cities_grouped.html";
try
{
using (XmlReader xml = XmlReader.Create(xmlFile))
using (XmlReader xslt = XmlReader.Create(xsltFile))
{
// Create a Processor instance
var processor = new Processor();
// Load the source document
XdmNode input = processor.NewDocumentBuilder().
Build(xml);
// Create a transformer for the stylesheet
XsltTransformer transformer = processor.NewXsltCompiler().
Compile(xslt).Load();
// Set the root node of the source document to be the initial context node
transformer.InitialContextNode = input;
// Create a serializer
var serializer = new Serializer();
serializer.SetOutputStream(new FileStream(outFile, FileMode.Create, FileAccess.Write));
// Transform the source XML
transformer.Run(serializer);
Console.WriteLine("Output written to " + outFile + Environment.NewLine);
}
}
catch (Exception e)
{
ConsoleColor currentConsoleColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("oops : " + e.Message);
Console.ForegroundColor = currentConsoleColor;
}
Console.Write("Press any key to exit ...");
Console.ReadKey();
}
}
}