这是我的 XSL:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.abc.org/1999/XSL/Transform">
<xsl:key name="effectLookup"
match="/InputAnimationConfigurationSchema/ConfigurationEffects/*"
use="@Id" />
<xsl:template match="/">
<html>
<body>
<h2></h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Widget</th>
<th>Trigger</th>
<th>effects</th>
</tr>
<xsl:apply-templates select=
"/InputAnimationConfigurationSchema/ConfigurationMappings/ConfigurationMap" />
</table>
</body>
</html>
</xsl:template>
<xsl:template match="ConfigurationMap">
<xsl:choose>
<xsl:when test="not(ConfigurationEffects)">
<xsl:call-template name="EmptyConfiguration">
<xsl:with-param name="widgetType" select="Widget/@Type" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="ConfigurationEffects/Effect" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="Effect">
<tr>
<td>
<xsl:value-of select="../../Widget/@Type"/>
</td>
<td>
<xsl:value-of select="../../Trigger/@Type"/>
</td>
<td>
<xsl:value-of select="key('effectLookup', ./text())/@DisplayName" />
</td>
</tr>
</xsl:template>
<xsl:template name="EmptyConfiguration">
<xsl:param name="widgetType" />
<tr>
<td>
<xsl:value-of select="$widgetType"/>
</td>
<td></td>
<td></td>
</tr>
</xsl:template>
</xsl:stylesheet>
这是我的 XML:
<InputAnimationConfigurationSchema>
<ConfigurationEffects>
<AEffect Id="1" DisplayName="A Effect">
</WipeEffect>
<BEffect Id="2" DisplayName="B Effect">
</FadeEffect>
<CEffect Id="3" DisplayName="C Effect">
</ConfigurationEffects>
<ConfigurationMappings>
<ConfigurationMap>
<Widget Type="All" Include="true"
NeedsMandatoryEffectConfiguration="true"/>
<Trigger Type="Show" />
<ConfigurationEffects>
<Effect>1</Effect>
<Effect>2</Effect>
<Effect>3</Effect>
<Effect>9</Effect>
</ConfigurationEffects>
</ConfigurationMap>
<ConfigurationMap>
<Widget Type="All" Include="true"
NeedsMandatoryEffectConfiguration="true"/>
<Trigger Type="Hide" />
<ConfigurationEffects>
<Effect>1</Effect>
<Effect>2</Effect>
<Effect>3</Effect>
<Effect>9</Effect>
</ConfigurationEffects>
</ConfigurationMap>
<ConfigurationMap>
<Widget Type="PIGWidget" Include="false"
NeedsMandatoryEffectConfiguration="true"/>
</ConfigurationMap>
<ConfigurationMap>
<Widget Type="PlaceHolder" Include="false"
NeedsMandatoryEffectConfiguration="true"/>
</ConfigurationMap>
</ConfigurationMappings>
</InputAnimationConfigurationSchema>
这是我的java代码:
package com.abc;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.File;
import java.io.OutputStream;
import javax.print.attribute.standard.MediaSize.Other;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class XmlToHtml
{
public static void main(String[] args)
{
String dataXML = args[0];
String inputXSL = args[1];
String outputHTML = args[2];
XmlToHtml xmltoHtml = new XmlToHtml();
try
{
xmltoHtml.transform(dataXML, inputXSL, outputHTML);
}
catch(TransformerConfigurationException e)
{
e.printStackTrace();
System.out.println("TransformerConfigurationException" + e);
}
catch(TransformerException e)
{
e.printStackTrace();
System.out.println("TransformerException" + e);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
System.out.println("FileNotFoundException" + e);
}
}
public void transform(String dataXML , String inputXSL, String outputHTML)
throws FileNotFoundException,TransformerException,TransformerConfigurationException
{
TransformerFactory tFactory = TransformerFactory.newInstance();
Source xslDoc = new StreamSource(inputXSL);
Source xmlDoc = new StreamSource(dataXML);
OutputStream htmlDoc = new FileOutputStream(outputHTML);
Transformer transformer = tFactory.newTransformer(xslDoc);
transformer.transform(xmlDoc, new StreamResult(htmlDoc));
}
}
当我执行 XmltoHtml.java 时,我收到类似 [Fatal Error] new_xmltohtml.xsl:1:1: Premature end of file 的错误。错误:“文件过早结束。” 致命错误:“无法编译样式表”
当我在 Eclipse 中将路径作为参数传递时。需要指导和帮助