0

假设我有这个 XML ......

<books>
  <book>
    <author>
    <title>
    <publish_date>
    <isbn_number>
  <book>
</books>

...我如何编写函数或使用内置函数来返回一个字符串,该字符串只是书的所有子元素名称的逗号分隔连接?像这样...

author,title,publish_date,isbn_number

我需要这个来打印 csv 文件中的第一行标题

4

1 回答 1

2

以下最小样式表适用于您的给定输入(修改为格式正确):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="book/*">
        <xsl:value-of select="local-name()"/>
        <xsl:if test="position() != last()">,</xsl:if>
    </xsl:template>
</xsl:stylesheet>
于 2011-11-07T22:58:17.493 回答