【发布时间】:2015-03-11 21:41:59
【问题描述】:
我有一个来自供应商的 XML 提要..
<?xml version="1.0" encoding="windows-1250"?>
<maps>
<map>
<sku>1534133010</sku>
<name>10 LED dekor. řetěz - sníh 2M IP44 modrá</name>
<price>165,0000</price>
<qty>0</qty>
</map>
</maps>
我需要按照公式换算价格:
=IIf([map]![price]<="100";[map]![price]*1,43;IIf([map]![price]<="300";[map]![price]*1,4;IIf([map]![price]<="500";[map]![price]*1,38;IIf([map]![price]<="700";[map]![price]*1,35;IIf([map]![price]>"1200";[map]![price]*1,34;0)))))
价格四舍五入为整数。
并完成转换为 CSV。
CSV 的期望输出:
sku,name,price,qty
1534133010,10 LED dekor. řetěz - sníh 2M IP44 modrá,220,0
我尝试关注但没有工作..
PHP 脚本:
<?php
$xml = new DOMDocument;
$xml->load('sample.xml');
$xsl = new DOMDocument;
$xsl->load('transformace.xsl');
$proc = new XSLTProcessor();
$proc->importStylesheet($xsl);
$newDOM = $proc->transformToDoc($xml);
$newDOM->formatOutput = true;
$newDOM->save("newfile.xml")
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="xml" encoding="windows-1250" />
<xsl:template match="/">
<maps>
<xsl:for-each select="SHOP/SHOPITEM">
<map>
<sku><xsl:value-of select="CODE"/></sku>
<name><xsl:value-of select="PRODUCT"/></name>
<price><xsl:value-of select="format-number( round(100*'price) div 100 ,"##0.00" )"/></price>
<qty><xsl:value-of select="AVAILABILITY"/></qty>
</map>
</xsl:for-each>
</maps>
</xsl:template>
</xsl:stylesheet>
有人知道怎么做吗?
【问题讨论】:
-
您尚未指定供应商。这是重要信息,您的问题缺少。 XML 是一种非常通用的文件格式。它通常传输更多信息和格式应用程序。您尚未提供要操作的文件的任何规范。因此,您的问题缺少文件格式规范的信息。我会投票关闭,因为不清楚,但让我看看是否可以快速关闭它而不是重复。 -- 另外请让自己熟悉编辑帮助以正确格式化您的问题,看看。
-
@user3533850 stackoverflow.com/help/someone-answers