这是我的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时,我收到的错误如[致命错误] new_xmltohtml.xsl:1:1:文件过早结束。 错误:'文件过早结束'。 致命错误:'无法编译样式表'
当我在日食中作为参数传递路径时。需要相同的指导和帮助
答案 0 :(得分:1)
没有开始标记
</WipeEffect>
在xml ..line number 4中 您的xml不是有效的xml。
答案 1 :(得分:0)
元素类型"AEffect", "BEffect", and "CEffect"
必须由输入XML中匹配的结束标记"</AEffect>", "</BEffect>" and "</CEffect>"
终止。