加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在具有XSLT的XML文档中获取根元素的标签名称?

发布时间:2020-12-16 08:03:42 所属栏目:百科 来源:网络整理
导读:我有兴趣将xml文档中的根元素的标签名称分配给xslt变量。例如,如果文档看起来像(减去DTD): foo xmlns="http://....." bar1/bar/foo 我想将字符串’foo’分配给一个xslt变量。有没有办法引用? 谢谢,马特 我想你想要检索最外层XML元素的名称。这可以像下面
我有兴趣将xml文档中的根元素的标签名称分配给xslt变量。例如,如果文档看起来像(减去DTD):
<foo xmlns="http://.....">
    <bar>1</bar>
</foo>

我想将字符串’foo’分配给一个xslt变量。有没有办法引用?

谢谢,马特

我想你想要检索最外层XML元素的名称。这可以像下面的XSL示例一样完成:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:variable name="outermostElementName" select="name(/*)" />

  <xsl:template match="/">
    <xsl:value-of select="$outermostElementName"/>
  </xsl:template>
</xsl:stylesheet>

请注意,XPath术语略有不同:

The top of the tree is a root node
(1.0 terminology) or document node
(2.0). This is what “/” refers to.
It’s not an element: it’s the parent
of the outermost element (and any
comments and processing instructions
that precede or follow the outermost
element). The root node has no name.

见http://www.dpawson.co.uk/xsl/sect2/root.html#d9799e301

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读