2
考虑下面的XML文档:如何创建具有各级层次结构的目录?
<Include>
<Feature Title="A">
<Feature Title="1" />
<Feature Title="2" />
</Feature>
<Feature Title="B">
<Feature Title="3">
<Feature Title="i" />
<Feature Title="ii" />
</Feature>
<Feature Title="4" />
</Feature>
</Include>
我需要生成一个文本文件,它看起来像:
; Header
A
A/1
A/2
B
B/3
B/3/i
B/3/ii
B/4
实现这一我最好的尝试是XSL样式表:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" omit-xml-declaration="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<xsl:text>; Header


</xsl:text>
<xsl:apply-templates select="//Feature" /></xsl:template>
<xsl:template match="Feature">
<xsl:value-of select="@Title" /><xsl:text>

</xsl:text>
</xsl:template>
</xsl:stylesheet>
但是这是产生输出:
; Header
A
1
2
B
3
i
ii
4
如何在输出中显示所有级别的层次结构?
良好的解决方案 - +1 – 2010-08-12 18:19:17
完美!感谢您的解决方案。 – 2010-08-12 18:23:40
@Brian Bassett:你很好!我很高兴这很有帮助。 – 2010-08-12 19:07:58