用于给定 XML 结构的 XSLT(对于 CSV)
我不知道如何制作 XML 的 XSLT 将其转换为 CSV。请为给定的 XML 结构编写 XSLT 代码,并尝试验证并考虑所有原始逗号和引号等。
<DROPSHIPITEMS>
<CREATED value="Thu Apr 21 23:17:39 BST 2011">
<PRODUCT ITEM='8101'>
<MODEL>FY316A</MODEL>
<EAN>5055071647109</EAN>
<NAME>Enchanted Twilight Flower Fairy 'Amethyst'</NAME>
<DESCRIPTION><![CDATA[<p> Twilight Fairy 'Amethyst'</p><p>This, Fairy.</p>]]></DESCRIPTION>
<DIMENSION><![CDATA[Height 31 - 32cm Width, 16 - 18.5cm Depth 12 - 13.5cm]]></DIMENSION>
<PRICE>16.63</PRICE>
<DELIVERY>I</DELIVERY>
<QUANTITY>224</QUANTITY>
<MIN_ORDER_QTY>1</MIN_ORDER_QTY>
<URL>http://www.abc-dropship.co.uk/gifts/product_info.php?products_id=8101</URL>
<IMAGE_URL>http://www.abc-dropship.co.uk/gifts/images/FY316A_001.jpg</IMAGE_URL>
<CATEGORIES>9003|100297</CATEGORIES>
<OPTIONS><![CDATA[B - Hand on Dress|A - Flower in Hand|Any]]></OPTIONS>
</PRODUCT>
</CREATED>
</DROPSHIPITEMS>
谢谢
I don't know how to make an XSLT for XML to convert it to CSV. Please code a XSLT for the given structure of XML and try to validate and consider the all original commas and quotes etc.
<DROPSHIPITEMS>
<CREATED value="Thu Apr 21 23:17:39 BST 2011">
<PRODUCT ITEM='8101'>
<MODEL>FY316A</MODEL>
<EAN>5055071647109</EAN>
<NAME>Enchanted Twilight Flower Fairy 'Amethyst'</NAME>
<DESCRIPTION><![CDATA[<p> Twilight Fairy 'Amethyst'</p><p>This, Fairy.</p>]]></DESCRIPTION>
<DIMENSION><![CDATA[Height 31 - 32cm Width, 16 - 18.5cm Depth 12 - 13.5cm]]></DIMENSION>
<PRICE>16.63</PRICE>
<DELIVERY>I</DELIVERY>
<QUANTITY>224</QUANTITY>
<MIN_ORDER_QTY>1</MIN_ORDER_QTY>
<URL>http://www.abc-dropship.co.uk/gifts/product_info.php?products_id=8101</URL>
<IMAGE_URL>http://www.abc-dropship.co.uk/gifts/images/FY316A_001.jpg</IMAGE_URL>
<CATEGORIES>9003|100297</CATEGORIES>
<OPTIONS><![CDATA[B - Hand on Dress|A - Flower in Hand|Any]]></OPTIONS>
</PRODUCT>
</CREATED>
</DROPSHIPITEMS>
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
它可以正确处理带逗号的字段和带双引号的字段。
编辑:差点忘了;该模板添加了一个带有字段名称的标题行。如果您不需要,第一个模板只需
Try this:
It correctly handles fields with a comma, and fields with double quotes as well.
EDIT: Almost forgot; this template adds a header line with field names in. If you don't need that, the first template just needs to be
将 XML 转换为逗号分隔与任何其他转换相同。以下按原样重现字段,除非它们在您仍然需要处理的每个产品中的顺序相同。该示例将帮助您入门:
顺便说一句,
�A;
添加换行符,对于 dos/windows,您可能还需要添加�D;
。更新:值中的逗号可以通过使用
translate()
函数将其替换为另一个字符来转义。To convert the XML to comma delimeted is just the same as any other transformation. The following reproduces the fields as-is so unless they are in the same order in every PRODUCT you need to handle that still. The example will get you started:
Btw, the
�A;
adds a newline, for dos/windows you might need to add a�D;
too.Update: commas in values can be escaped by replacing them with another character using the
translate()
function.