简体   繁体   English

Google App Engine(Java)中的XSLT

[英]XSLT in Google App Engine (Java)

I have this well-formed XSLT file to convert XML files into slightly different XML files. 我有这个格式良好的XSLT文件,可以将XML文件转换为稍有不同的XML文件。 My setup works when I run the tranformation in plain Java, but when I try to run my code on Google App Engine it crashes when I try to load the XSLT file, with the following error message: 当我使用纯Java运行转换时,我的设置可以正常运行,但是当我尝试在Google App Engine上运行代码时,当我尝试加载XSLT文件时崩溃,并显示以下错误消息:

ERROR:  'null'
FATAL ERROR:  'Could not compile stylesheet'
javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(Unknown Source)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(Unknown Source)

Java: Java:

(Something goes wrong here) (这里出了问题)

    InputStream is = context.getResourceAsStream("/xslt/add_spaces_and_ids.xslt");
    if (is == null) {
        throw new NullPointerException("File could not be found");
    }
    Source xsltSource = new StreamSource(is);
    Transformer transformer = factory.newTransformer(xsltSource);
    return transformer;

XSLT: XSLT:

(Should be nothing special) (应该没什么特别的)

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:strip-space elements="*"/>
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="kop">
    <xsl:variable name="kopText">
      <xsl:value-of select="."/>
    </xsl:variable>
    <xsl:variable name="titelText">
      <xsl:value-of select="titel"/>
    </xsl:variable>
    <!-- Add a space -->
    <xsl:text> </xsl:text>
    <xsl:copy>
      <xsl:attribute name="id">
        <xsl:value-of select="generate-id()" />
      </xsl:attribute>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="node()">
    <xsl:text> </xsl:text>
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="@*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*" />
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

How can I fix this? 我怎样才能解决这个问题?

I had some conflicting libraries in my build path: 我的构建路径中有一些冲突的库:

xercesImps.jar , xml-apis.jar , and serializer.jar xercesImps.jarxml-apis.jarserializer.jar

Removing these from the build path, while keeping saxon, resolved my issues. 从构建路径中删除这些文件,同时保留saxon,可以解决我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM