【发布时间】:2021-03-02 11:09:43
【问题描述】:
我需要将 XML 文件转换为 CSV。
预期输出:
tag1 tag2 Typearray
Name1 Name2 1
Name1 Name2 13
使用 XSLT 只能获得一条记录,而数组中的第二条记录被拒绝。
tag1,tag2,CommOffer,TypeArray
name1,name2,1
您能告诉我如何使用 XSLT 读取数组值吗?
示例 XML:
<Master2>
<Child1>
<tag1>name1</tag1>
<tag2>name2</tag2>
<TypeArray>
<value>1</value>
<value>13</value>
</TypeArray>
</Child1>
</Master2>
</Master1>
XSLT:
<xsl:template match="/">
<xsl:text>tag1,tag2,TypeArray</xsl:text>
<xsl:text>
</xsl:text>
<xsl:for-each select="Master1/Master2/Child1">
<xsl:call-template name="CsvEscape"><xsl:with-param name="value" select="normalize-
space(tag1)"/></xsl:call-template>
<xsl:text>,</xsl:text>
<xsl:call-template name="CsvEscape"><xsl:with-param name="value" select="normalize-
space(tag2)"/></xsl:call-template>
<xsl:text>,</xsl:text>
<xsl:call-template name="CsvEscape"><xsl:with-param name="value" select="TypeArray/value"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
【问题讨论】:
-
你标记了这个sas - 你在用SAS写这个吗?
-
是的,我在 sas 9.4M2 中使用 PROC XSL