我正在尝试展平以下 XML:
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://pretend.namespace">
<record>
<first>1</first>
<second>2</second>
<tricky>
<taxing>3</taxing>
<mayhem>
<ohno>4</ohno>
<boom>5</boom>
</mayhem>
</tricky>
</record>
<record>
<first>1</first>
<second>2</second>
<tricky>
<taxing>3</taxing>
<mayhem>
<ohno>4</ohno>
<boom>5</boom>
</mayhem>
</tricky>
</record>
<record>
<first>1</first>
<second>2</second>
<tricky>
<taxing>3</taxing>
<mayhem>
<ohno>4</ohno>
<boom>5</boom>
</mayhem>
</tricky>
</record>
</root>
每条记录一行,丢弃记录中的复杂结构。
1,2,3,4,5
1,2,3,4,5
1,2,3,4,5
使用这个 XSLT
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:p="http://pretend.namespace">
<xsl:strip-space elements="*"/> <!-- remove unwanted whitespace? -->
<!-- Match every p:record -->
<xsl:template match="p:record">
<xsl:apply-templates/> <!-- now we're inside a <record> do what you can with the contents then give a line return -->
<xsl:text>
</xsl:text><!-- this is a line return -->
</xsl:template>
<xsl:template match="p:record//*">
<xsl:value-of select="."></xsl:value-of><xsl:text>,</xsl:text>
</xsl:template>
<xsl:template match="text()"/> <!-- WORKS: prevents "default output" to aid debugging -->
</xsl:stylesheet>
但是尽管尝试了几个小时,我还是无法让它访问每个后代并用逗号分隔它们,我得到了这个:
1,2,345,
1,2,345,
1,2,345,
我需要做什么才能让它单独对待所有孙子及以下?(每行的最后一个逗号不是问题)
谢谢!
编辑:this question之后的讨论表明Herong Yang博士的Notepad ++ XML工具似乎只支持XSLT 1.0