這是我的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:文件過早結束。 錯誤:'文件過早結束'。 致命錯誤:'無法編譯樣式表'
當我在日食中傳遞路徑作爲參數。極品相同
「在日食中傳遞路徑作爲參數」 - _full_路徑或只是一個相對路徑?如果是後者,你確定Java過程的工作目錄是你期望的嗎? –
好吧,它現在工作正常..感謝您的支持和幫助 –