8,906
社区成员
发帖
与我相关
我的任务
分享
<?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>
<?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>
#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);
}
}
//Create a new XslTransform object.
XslTransform xslt = new XslTransform();
//Load the stylesheet.
xslt.Load(@"E:\Test\test.xslt");
//Create a new XPathDocument and load the XML data to be transformed.
XPathDocument mydata = new XPathDocument(@"E:\Test\results.xml");
//Create an XmlTextWriter which outputs to the console.
XmlWriter writer = new XmlTextWriter(Console.Out);
//Transform the data and send the output to the console.
xslt.Transform(mydata,null,writer, null);
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
/**
* Use the TraX interface to perform a transformation in the simplest manner possible
* (3 statements).
*/
public class SimpleTransform {
public static void main(String[] args)
throws TransformerException, TransformerConfigurationException,
FileNotFoundException, IOException {
// Use the static TransformerFactory.newInstance() method to instantiate
// a TransformerFactory. The javax.xml.transform.TransformerFactory
// system property setting determines the actual class to instantiate --
// org.apache.xalan.transformer.TransformerImpl.
TransformerFactory tFactory = TransformerFactory.newInstance();
// Use the TransformerFactory to instantiate a Transformer that will work with
// the stylesheet you specify. This method call also processes the stylesheet
// into a compiled Templates object.
Transformer transformer = tFactory.newTransformer(new StreamSource("html.xslt"));
// Use the Transformer to apply the associated Templates object to an XML document
transformer.transform(new StreamSource("results7.xml"), new StreamResult(new
FileOutputStream("out.html")));
System.out.println("************* The result is in birds.out *************");
}
}