【问题标题】:In Xalan XSLT 1.0, need a function to return all child element names在 Xalan XSLT 1.0 中,需要一个函数来返回所有子元素名称
【发布时间】:2011-11-07 22:48:32
【问题描述】:

假设我有这个 XML...

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

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

author,title,publish_date,isbn_number

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

【问题讨论】:

    标签: xml xslt xpath xalan


    【解决方案1】:

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

    <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>
    

    【讨论】:

    • @RaffiM - for-each 可以做到这一点,但绝对没有必要。
    • @RaffiM - 尝试将模板匹配更改为 match="/books/book/*"
    猜你喜欢
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-27
    相关资源
    最近更新 更多