これは私の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 のようなエラーが発生します。エラー: 「ファイルの終わりが早すぎます。」致命的なエラー: 「スタイルシートをコンパイルできませんでした」
日食でパスを引数として渡しました。同じためのガイダンスとヘルプが必要