【发布时间】:2023-03-21 17:25:01
【问题描述】:
我想将 file.xml 解释为 file.txt,这不是问题,但是当我尝试在不同的标签中“获取”许多东西时。
请看一下我的 file.xml:
<racine>
<balise1>
<info>
<Commercial>1000</Commercial>
<OrdId>42</OrdId>
<CustomerId>314159</CustomerId>
</info>
</balise1>
<balise2>
<info2>
<Quantity>1</Quantity>
<Price>10.0</Price>
<Currency>CHF</Currency>
</info2>
</balise2>
</racine>
我想要这个输出;
Commercial,Order,CustomerId,Quantity,Price,Currency
1000,42,314159,1,10.0,CHF
我尝试了很多解决方案,但我是 XSLT 的菜鸟。
这是我的 xslt 示例:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSl/Transform">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:text>Commercial,OrdId,CustomerId,Quantity,Price,Currency</xsl:text>
<xsl:text>
</xsl:text>
<xsl:apply-templates select="racine"/>
</xsl:template>
<xsl:template match="racine">
<xsl:apply-templates select="balise1/info"/>
</xsl:template>
<xsl:template match="info">
<xsl:value-of select="Commercial"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="OrdId"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="CustomerId"/>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="info">
<xsl:apply-templates select="balise2/info2"/>
</xsl:template>
<xsl:template match="info2">
<xsl:value-of select="ItemQuantity"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="PriceValue"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="CurrencyCode"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
-
能否请您添加所需的输出以及 - 如果您已经尝试过 - 您当前的 xslt。
-
请阅读Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - 总结是这不是解决志愿者的理想方式,并且可能会适得其反。请不要将此添加到您的问题中。