在 XSLT 中选择当前元素名称 [英] selecting current element name in XSLT

查看:26
本文介绍了在 XSLT 中选择当前元素名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要输出应用xpath表达式后返回的元素名称,例如

I need to output the element name which is being returned after applying the xpath expression for example

<xsl:for-each select="//element">
      <xsl:value-of select="**{elementname}**"></xsl:value-of>
      <xsl:text>:</xsl:text>
      <xsl:value-of select="current()"/>
      <xsl:value-of />
</xsl:for-each>

如何将 {elementname} 替换为某个 xpath,以便获取元素名称而不是当前值

How can i replace {elementname} to some xpath so that I can get the element name instead of current value

推荐答案

<xsl:value-of select="name()" />

旁注:除非您绝对没有其他可能性,否则请避免使用 // 速记.它看起来又快又容易,但事实并非如此——它在计算上非常昂贵,而且 90% 的时间你都不需要它.

Side note: Avoid the // shorthand unless you absolutely have no other possibility. It seems quick and easy, but it isn't - it is computationally very expensive, and 90% of the time you don't need it.

尽可能编写规范的替换 XPath 表达式.即使是一般的东西/*/*/node//node 运行得快得多.

Write a canonical replacement XPath expression whenever you can. Even something as generic as /*/*/node runs much faster than //node.

这篇关于在 XSLT 中选择当前元素名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆