我有一个报告生成器工具,可以为不同类型的报告生成 XML 文档。这些 XML 文档中的每一个都有一组字段(以下 XML 文档中的报告:列),用于描述其中的实际数据(以下 XML 文档中的报告:行)。由于字段列表是动态的并且对于每种报告都在不断变化,因此如何编写使用“字段”将数据转换为 csv 文件的通用 XSL 模板。
我的示例 XML 文档:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<reporting:root xmlns:reporting="http://www.something.net/reporting">
<reporting:default0 reporting:type="Portfolio">
<reporting:header>
<reporting:configuration>
<reporting:columns>
<reporting:column reporting:group="instrument" reporting:name="Ident" reporting:tag="ident" reporting:type="int"/>
<reporting:column reporting:group="prices" reporting:name="Last (Time)" reporting:tag="lastTime" reporting:type="string"/>
<reporting:column reporting:group="noGroup" reporting:name="RIC" reporting:tag="ric" reporting:type="string"/>
<reporting:column reporting:group="instrument" reporting:name="Reference" reporting:tag="reference" reporting:type="string"/>
<reporting:column reporting:group="result" reporting:name="Currency" reporting:tag="currency" reporting:type="string"/>
</reporting:columns>
</reporting:configuration>
</reporting:header>
<reporting:window reporting:Id="36674" reporting:level="0" reporting:name="MY_PORTFOLIO" reporting:parentId="11991">
<reporting:line reporting:Id="67520135" reporting:level="1" reporting:name="INTERNATIONAL BUSINESS MACHINES CORP" reporting:parentId="36674" reporting:positionType="0">
<reporting:ident>643633</reporting:ident>
<reporting:reference>IBM.USD</reporting:reference>
<reporting:currency>USD</reporting:currency>
</reporting:line>
<reporting:line reporting:Id="67520179" reporting:level="1" reporting:name="GENERAL ELECTRIC CO" reporting:parentId="36674" reporting:positionType="0">
<reporting:ident>643635</reporting:ident>
<reporting:ric>GE.N</reporting:ric>
<reporting:reference>GE.USD</reporting:reference>
<reporting:currency>USD</reporting:currency>
</reporting:line>
</reporting:window>
</reporting:default0>
</reporting:root>
我需要看到格式如下的输出:
ident,lastTime,ric,reference,currency
643633,,,IBM.USD,USD
643635,,GE.N,GE.USD,USD
我做了一些工作,但它完成了一半。找不到如何处理“动态”字段列表并将它们用作描述实际数据的标签。
有人可以帮忙吗?
谢谢。