如何将以属性为中心的XML转换为以元素为中心,以便我可以导入Access / Excel?

时间:2016-05-27 13:05:38

标签: xml xslt

好的,所以我在一个以属性为中心的XML导出数据的电子商务平台上工作。我需要将其转换为Element Centric XML,然后我可以将其转换为某种数据表格式,以便我组织中的其他团队可以轻松阅读。我在这里的老线程中找到了一个潜在的答案(见下文),但由于我的XML体验仅限于使用它进行Soap UI测试,我不知道如何使用该解决方案,所以也许这里的一些人可以解释它或者与其他如何完成我需要做的想法相吻合。

我使用的XML类似于此类,但更长的层次更长。

  <ns2:order id="">
  <ns2:order-header>
     <ns2:order-process-info>
        <ns2:status></ns2:status>
        <ns2:creation-date></ns2:creation-date>
     </ns2:order-process-info>
     <order-info>
        <document-no></document-no>
        <store></store>
        <locale></locale>
        <currency></currency>
        <calculation-rule-set></calculation-rule-set>
        <order-reference-id></order-reference-id>
     </order-info>
     <ns2:customer>
        <ns2:customer-id></ns2:customer-id>
        <ns2:customer-type-id></ns2:customer-type-id>
        <ns2:calculation-type></ns2:calculation-type>
        <ns2:first-name></ns2:first-name>
        <ns2:last-name></ns2:last-name>
        <ns2:company-name1></ns2:company-name1>
        <ns2:department />
        <ns2:taxationid />
        <ns2:user-id />
     </ns2:customer>

然后我发现了这个XSLT,但我的问题是如何使用它? XML需要哪些信息进入XSLT,我从哪里运行它?我自己试图找到这个答案,但没有用。

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL   /Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="Catalogue/App/@*">
<xsl:element name="{name()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>

<xsl:template match="Catalogue/App/Note[1]">
<Note1><xsl:apply-templates select="@*|node()"/></Note1>
</xsl:template>

<xsl:template match="Catalogue/App/Note[2]">
<Note2><xsl:apply-templates select="@*|node()"/></Note2>
</xsl:template>

<xsl:template match="Catalogue/App/Note[3]">
<Note3><xsl:apply-templates select="@*|node()"/></Note3>
</xsl:template>

<xsl:template match="Catalogue/App/Note[4]">
<Note4><xsl:apply-templates select="@*|node()"/></Note4>
</xsl:template>

<xsl:template match="Catalogue/App/Note[5]">
<Note5><xsl:apply-templates select="@*|node()"/></Note5>
</xsl:template>


</xsl:stylesheet>

0 个答案:

没有答案