导入XML信息的Excel当缺少的元素
问题描述:
我有下面的XML文件:导入XML信息的Excel当缺少的元素
<toc label="My information" href="index.html">
<topic label="Main page 1" href="topics/one.html">
<topic label="1a" href="topics/1a.html"/>
<topic label="1b" href="topics/1b.html"/>
</topic>
<topic label="Main page 2" href="topics/two.html">
<topic label="2a" href="topics/2a.html"/>
<topic label="2b" href="topics/2b.html"/>
</topic>
</toc>
这是伟大的,但我希望能够在“主页面1”和“主页面2”中分别获得一排。我怎样才能让Excel包含这些行?
答
我工作围绕这通过运行通过XSL的XML是复制有孩子的所有节点:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="toc">
<topic label="{@label}" href="{@topic}">
<xsl:apply-templates/>
</topic>
</xsl:template>
<xsl:template match="topic">
<topic label="{@label}" href="{@href}">
<!-- if topic has children, insert another copy here -->
<xsl:if test="topic">
<topic label="{@label}" href="{@href}"/>
</xsl:if>
<xsl:apply-templates/>
</topic>
</xsl:template>
</xsl:stylesheet>