【问题标题】:XSLT - checking the total size of //text()XSLT - 检查 //text() 的总大小
【发布时间】:2016-06-02 09:03:08
【问题描述】:

我试图将 XML 文件的所有文本作为一个节点而不是一系列节点来获取,以便检查整个文本的大小。

XML

<root>
 <a>a word</a>
 <b>Some text <c>in</c> the file</b>
</root>

XSL

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:variable name="$text" select="/root/descendant-or-self::*/text()" />
    <xsl:message select="string-length($text)"/>
  </xsl:template>
</xsl:stylesheet>

这不起作用,因为我在$text 中得到一个序列而不是一个简单的字符串。

我该怎么做?

【问题讨论】:

    标签: xml xslt


    【解决方案1】:

    试试这个 XSLT 1.0

    <xsl:template match="/">
      <xsl:variable name="text" select="string(.)" />
      <xsl:message>
        <xsl:value-of select="string-length($text)"/>
      </xsl:message>
    </xsl:template>
    

    【讨论】:

      猜你喜欢
      • 2011-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      相关资源
      最近更新 更多