【发布时间】:2019-10-21 14:41:37
【问题描述】:
我正在尝试运行与将 xml 转换为 csv 相关的 Java 代码。 必须使用 xsl 文件。但是,代码中似乎存在一些问题,因为在运行 Java 代码时,我收到一个空的 csv 文件(只有每列的标题)。 Java 代码工作得很好,因为我将它与一些测试数据一起使用。
所以问题出在 xsl 文件上。
我的 xml 文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<fcd-export xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/fcd_file.xsd">
<data time="0.00">
<mobil id="1" x="23.774532" y="37.967331" angle="229.707852" type="car" speed="0.000000" pos="5.100000" lane="32041497_0" slope="0.000000"/>
<mobil id="2" x="23.758638" y="37.971738" angle="38.291786" type="car" speed="0.000000" pos="5.100000" lane="265887574#0_0" slope="0.000000"/>
</data>
<data time="1.00">
<mobil id="1" x="23.774522" y="37.967326" angle="230.554332" type="car" speed="1.000000" pos="6.100000" lane="32041497_0" slope="0.000000"/>
<mobil id="2" x="23.758645" y="37.971745" angle="38.291786" type="car" speed="1.000000" pos="6.100000" lane="265887574#0_0" slope="0.000000"/>
</data>
<data time="2.00">
<mobil id="1" x="23.774503" y="37.967316" angle="233.076683" type="car" speed="2.000000" pos="8.100000" lane="32041497_0" slope="0.000000"/>
<mobil id="2" x="23.758660" y="37.971759" angle="38.291786" type="car" speed="2.000000" pos="8.100000" lane="265887574#0_0" slope="0.000000"/>
</data>
而我的 xsl 文件:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" >
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
x
<xsl:for-each select="/data">
<xsl:value-of select="/data/mobil/@x" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我想要的是在第 5-7 行声明我想要属性的值:x of mobil etiquette。
【问题讨论】:
-
1. 您的 XML 文件似乎被截断:
fcd-export没有结束标记。 2. 如果fcd-export是根元素,那么您的XSLT 将不会做任何事情,因为它假定data是根元素。 -
嗯,实际上,我的意思是在真实文件中最后有 。