简体   繁体   English

使用Java将xml更改为html

[英]Using Java to change xml to html

I am using java code to create a html document. 我正在使用Java代码创建html文档。 I have an xsl stylesheet and some xml that I want to create the html from. 我有一个xsl样式表和一些我想从中创建html的xml。

I am using the TransformerFactory method to do this. 我正在使用TransformerFactory方法来执行此操作。 My problem is that when it creates the html file, when you open it you see a blank page but the code is there. 我的问题是,当它创建html文件时,当您打开它时,您会看到一个空白页,但是代码在那里。 The issue is that when the html is created it uses a javascript file (which is used in the xsl code) and it doesn't add the </script> tag at the end of it but it is used in the xsl. 问题在于,创建html时,它使用的是javascript文件(xsl代码中使用了javascript文件),并且没有在其末尾添加</script>标记,但在xsl中使用了html文件。

So in the xsl it is as follows: 因此,在xsl中,它如下所示:

<script src="URL" language = "javascript" type = "text/javascript"></script>

but when the html creates it, it does: 但是当html创建它时,它会:

<script src="URL" language="javascript" type="text/javascript"/>

and it doesn't include the </script> tag. 而且它不包含</script>标记。 Instead it uses the / at the end to close it. 而是使用结尾的/来关闭它。 For some reason the html doesn't like this and when I insert the tag in manually it works fine, but I want it to include the tag itself so it will open properly. 出于某种原因,html不喜欢这种样式,当我手动插入标签时,它可以正常工作,但是我希望它包含标签本身,以便可以正确打开。

Any idea's on how to do this. 关于如何执行此操作的任何想法。

Your help is much appreciated. 非常感谢您的帮助。

告诉XSLT使用output方法元素输出HTML。

<xsl:output method="html"/>

Simply make sure the script tag is not empty. 只需确保脚本标记不为空。 Put in a dummy comment, for example. 例如,输入一个虚拟注释。 This way you force the XSLT processor to close the tag explicitly, regardless of any other settings. 这样,无论任何其他设置如何,您都强制XSLT处理器显式关闭标签。

您是否尝试过<xsl:text><xsl:copy>

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

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