java - 出现文件过早结束错误

标签 java xslt

这是我的 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: 文件过早结束的错误。 错误:“文件过早结束。” fatal error :“无法编译样式表”

当我在 Eclipse 中将路径作为参数传递时。需要指导和帮助

最佳答案

没有开始标记

</WipeEffect>

在你的 xml ..行号 4 中 您的 xml 不是有效的 xml。

关于java - 出现文件过早结束错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17210953/

相关文章:

java - 加载Java内部类

java - 失败时在 ANT 中执行默认任务

c# - 给定的路径格式不支持 c#

xml - 如何使用 XSL 在 href 中查找具有特定关键字的 <a> 元素?

xslt - 创建节点集并作为参数传递

java - 如何使用 Spring WebSockets 和 Undertow 接收大于 16kB 的 WebSocket 消息

java - 我通过套接字发送的 int 值与接收到的 int 值不同(Java)

java - 为什么 finally 中的代码即使在 try block 中返回也会执行?

php - 使用 php 将 xml 转换为 html