【发布时间】:2016-09-20 18:54:14
【问题描述】:
我完全是 XSLT 的菜鸟,我一直在环顾四周,并试图为此找到答案。下面的 XSLT 适用于我的小示例文件,但实际的 xml 文件为 200 mb,我等了 20 分钟才取消它。我的问题是,有没有更快的方法来做到这一点?我的 XSLT 是否草率?我在 Access 中使用它是因为我别无选择。
这是一个 XML 示例:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ACES version="3.0">
<App action="A" id="1">
<BaseVehicle id="119703">2013 Acura MDX </BaseVehicle>
<EngineBase id="5816">V6 3.7L (224cid 3664cc) 3.54x3.78in/90.0x96.0mm</EngineBase>
<FuelType id="5">GAS</FuelType>
<Qty>1</Qty>
</App>
<App action="A" id="2">
<BaseVehicle id="119703">2013 Acura MDX </BaseVehicle>
<EngineBase id="2147">V6 3.7L (-cid 3664cc) 3.54x3.78in/90.0x96.0mm</EngineBase>
<FuelType id="5">GAS</FuelType>
<Qty>1</Qty>
</App>
</ACES>
这是我正在使用的 XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//ACES/App/BaseVehicle">
<BaseID><xsl:value-of select="@id"/></BaseID>
<BaseName><xsl:value-of select="//ACES/App/BaseVehicle"/></BaseName>
</xsl:template>
<xsl:template match="//ACES/App/EngineBase">
<EngineID><xsl:value-of select="@id"/></EngineID>
<EngineName><xsl:value-of select="//ACES/App/EngineBase"/></EngineName>
</xsl:template>
<xsl:template match="//ACES/App/FuelType">
<FuelID><xsl:value-of select="@id"/></FuelID>
<FuelName><xsl:value-of select="//ACES/App/FuelType"/></FuelName>
</xsl:template>
</xsl:stylesheet>
我真正想要的只是@id 和文本值。所以像:
BaseID BaseVehicle EngineID EngineBase
119703 2013 Acura MDX 5816 V6 3.7L (224cid 3664cc) 3.54x3.78in/90.0x96.0mm
以第一个为例(我想要按此顺序列出所有内容)
有没有更快的方法可以做到这一点?
谢谢
【问题讨论】:
-
您想要 XML 输出吗?那么请显示预期的xml,或者你想要文本,然后使用
<xsl:output method="text"/> -
您的 XML 格式不正确 - BaseVehicle 结束标签在哪里?
-
@MichaelKay - BaseVehicle 的末端隐藏在右侧。我想知道这是否相当于大约 20Mb 的空白;-)
-
不幸的是其他人为我制作了文件,所以我无能为力!