gpt4 book ai didi

java - 尝试使用 eclipse 运行 xslt for xml 但它不起作用

转载 作者:行者123 更新时间:2023-12-02 05:45:22 24 4
gpt4 key购买 nike

我正在尝试运行 .xslt 以在 Eclipse 中显示从 .xml 到 html 页面的一些信息。我运行它,并且 eclipse 生成一个 .out.xml 文件,当我尝试使用 chrome 运行时,我收到消息:

This XML file does not appear to have any style information associated with it.

我对此完全陌生,所以我不知道发生了什么......

XML 文件:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="html_xml.xslt"?>
<CarModel>
<Audi model = "TT" year = "2006" starting_price = "33.000$">
<type>sport</type>
<horse_power>222hp</horse_power>
<drivetrain>quattro</drivetrain>
<transmission>6_Manual</transmission>
</Audi>
<Mercedes model = "W222_S400" year = "2013" starting_price = "63.000$">
<type>luxury</type>
<horse_power>302hp</horse_power>
<drivetrain>front_wheel_drive</drivetrain>
<transmission>7_Automatic</transmission>
</Mercedes>
<BMW model = "X3_xDrive35i" year = "2010" staring_price = "40.000$">
<type>crossover_SUV</type>
<horse_power>302hp</horse_power>
<drivetrain>quattro</drivetrain>
<transmission>6_Manual</transmission>
</BMW>
</CarModel>

XSLT 文件:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<html><body><h2> Car Model Info </h2>
<table border="1">
<xsl:apply-templates mode="elem" select="/*"/>
</table></body>
</html>
</xsl:template>
<xsl:template mode="elem" match="/*">
<tr bgcolor="#9acd32">
<td><xsl:value-of select="name()"/></td>
<td><xsl:apply-templates mode="child" select="/*/*"/> (c) </td>
<td><xsl:apply-templates mode="attr" select="/*/@*"/> (a) </td>
</tr>
</xsl:template>
<xsl:template mode="child" match="/*/*">
<xsl:value-of select="name()"/>
</xsl:template>
<xsl:template mode="attr" match="/*/@*">
<xsl:value-of select="name()"/>
</xsl:template>

</xsl:stylesheet>

XSLT 输出:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<html><body><h2> Car Model Info </h2>
<table border="1">
<xsl:apply-templates mode="elem" select="/*"/>
</table></body>
</html>
</xsl:template>
<xsl:template mode="elem" match="a:*">
<tr bgcolor="#9acd32">
<td><xsl:value-of select="name()"/></td>
<td><xsl:apply-templates mode="child" select="/*/*"/> (c) </td>
<td><xsl:apply-templates mode="attr" select="/*/@*"/> (a) </td>
</tr>
</xsl:template>
<xsl:template mode="child" match="/*/*">
<xsl:value-of select="name()"/>
</xsl:template>
<xsl:template mode="child" match="/*/@*">
<xsl:value-of select="name()"/>
</xsl:template>

</xsl:stylesheet>

最佳答案

Eclipse 似乎更喜欢用 .xsl 命名的样式表,而不是 .xslt。至少,当我在我的环境中尝试你的样式表和输入 XML 时,我将其重命名为并将 XML 的第二行更改为

<?xml-stylesheet type="text/xsl" href="html_xml.xsl"?>

并将 XSL 的第二行更改为

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

正如另一条评论中所建议的。之后,以下内容对我有用:

  1. 名为 input.xmlhtml_xml.xsl 的文件位于 Eclipse 项目的同一目录中
  2. 右键单击 input.xml 并选择运行方式 -> XSL 转换
  3. 查找生成的名为 input.out.html 的文件

关于java - 尝试使用 eclipse 运行 xslt for xml 但它不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24125596/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com