问个样式转换的问题(两种转换方式的结果不同)
我有三个文件:
results.xml(待转换的源文件):
test.xslt(样式文件):
program.cs(用于转换的C#程序源代码):
results.xml(待转换的源文件):
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Test.xslt"?>
<results>
<NS:Clip xmlns:NS="http://myFootballMatch" src="http://Multimedia/FootballMatches/worldcupChileArgentina2.rm" IfIn="false">
<NS:Action>角球</NS:Action>
<NS:Duration>
<NS:StartTime>00:32:54Z</NS:StartTime>
<NS:EndTime>00:33:06Z</NS:EndTime>
</NS:Duration>
<NS:Team>智利</NS:Team>
<NS:Player>7号</NS:Player>
<NS:Remark>球没进</NS:Remark>
</NS:Clip>
<NS:Clip xmlns:NS="http://myFootballMatch" src="http://Multimedia/FootballMatches/worldcupChileArgentina2.rm" IfIn="false">
<NS:Action>角球</NS:Action>
<NS:Duration>
<NS:StartTime>00:56:13Z</NS:StartTime>
<NS:EndTime>00:56:33Z</NS:EndTime>
</NS:Duration>
<NS:Team>阿根廷</NS:Team>
<NS:Player>8号里克尔梅</NS:Player>
<NS:Remark>球没进,又获得一个角球</NS:Remark>
</NS:Clip>
<NS:Clip xmlns:NS="http://myFootballMatch" src="http://Multimedia/FootballMatches/worldcupChileArgentina2.rm" IfIn="false">
<NS:Action>角球</NS:Action>
<NS:Duration>
<NS:StartTime>00:56:34Z</NS:StartTime>
<NS:EndTime>00:56:56Z</NS:EndTime>
</NS:Duration>
<NS:Team>阿根廷</NS:Team>
<NS:Player>15号达莱桑德罗</NS:Player>
<NS:Remark>球没进</NS:Remark>
</NS:Clip>
</results>
test.xslt(样式文件):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:matchs="http://myFootballMatch" exclude-result-prefixes="#default matchs">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="results">
<html xmlns="http://www.w3.org/1999/xhtml" lang="UTF-8">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>新闻</title>
<link href="news.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="results/matchs:Clip">
<table>
<tbody>
<tr>
<th>Item<xsl:value-of select="position()"/></th>
</tr>
<tr>
<td class="title">
<b>动作:</b>
</td>
<td><xsl:value-of select="matchs:Action"/></td>
</tr>
<tr>
<td class="title">
<b>队名:</b>
</td>
<td><xsl:value-of select="matchs:Team"/></td>
</tr>
<tr>
<td class="title">
<b>队员名:</b>
</td>
<td><xsl:value-of select="matchs:Player"/></td>
</tr>
<tr>
<td class="title">
<b>是否有进球:</b>
</td>
<td>
<xsl:variable name="isGoal" select="@IfIn"/>
<xsl:if test="$isGoal = 'false'">
<xsl:text>否</xsl:text>
</xsl:if>
<xsl:if test="$isGoal = 'true'">
<xsl:text>是</xsl:text>
</xsl:if>
</td>
</tr>
<tr>
<td class="title">
<b>评论:</b>
</td>
<td><xsl:value-of select="matchs:Remark"/></td>
</tr>
</tbody>
</table>
<br />
</xsl:template>
</xsl:stylesheet>
program.cs(用于转换的C#程序源代码):
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
#endregion
using System.IO;
using System.Xml;
using System.Xml.Query;
public class Sample {
public static void Main() {
// Create the XsltCommand object.
XsltCommand xslt = new XsltCommand();
xslt.OnMessageEvent += new QueryEventHandler(MessageCallBack);
// Compile the stylesheet.
xslt.Compile(@"E:\Test\Test.xslt");
// Transform the file.
xslt.Execute(@"E:\Test\results.xml", @"E:\Test\output.html");
}
// Display any event messages.
public static void MessageCallBack(object sender, QueryEventArgs e) {
Console.WriteLine("Message received: {0}", e.Message);
}
}
...全文
相关推荐
WPF 实现RadioButton样式两种方式,vs2010
WPF 实现RadioButton样式两种方式:1资源样式 2代码调用资源样式 ,vs2010
两种不同坐标系之间的转换
详细解释坐标系的转换运算,是测绘论文的良好参考资料,最基础的东西
原生js更改css样式的两种方式
本文主要介绍了原生js更改css样式的两种方式,具有很好的参考价值,下面跟着小编一起来看下吧
Vue单页应用引用单独的样式文件的两种方式
给大家介绍Vue单页应用如何引用单独的样式文件,本文以css文件为例,通过两种方式给大家介绍的非常详细,需要的朋友参考下吧
bin excel两种文件互相转换
bin excel两种文件互相转换。利用C#编写,主要提供给开发人员使用,可以将bin与xls文件互相转换。 因为xls便于查看,如果xls会使用函数的,可以在xls中再增加函数实现数据计算处理。


