是否有 XSLT name-of 元素? [英] Is there an XSLT name-of element?

查看:27
本文介绍了是否有 XSLT name-of 元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 XSLT 中有

获取元素的值,但是有什么可以选择元素的标签名吗?

在这样的情况下:

<!-- 必需的东西--><姓名>罗伯特</姓名><!-- 可选的东西,未来扩展的自由形式.使用 XMLSchema 的 xsd:any --><专业>程序员</专业><hobby>摄影</hobby></人><xsl:for-each select="person"><xsl:tag-of select="."/>:<xsl:value-of select="."/></xsl:for-each>

获得这样的输出:

<块引用>

姓名:罗伯特职业:程序员爱好:摄影

当然上面的XSLT不会编译,因为

 

不存在.但这怎么可能呢?

解决方案

这会给你当前的元素名称(标签名称)

OP-Edit: 这也能解决问题:

In XSLT there is the

<xsl:value-of select="expression"/>

to get the value of an element, but is there something to select the tag-name of the element?

In a situation like this:

<person>
  <!-- required stuff -->
  <name>Robert</name>
  <!-- optional stuff, free form for future extension. 
       Using XMLSchema's xsd:any -->
  <profession>programmer</profession>
  <hobby>photography</hobby>
</person>

<xsl:for-each select="person">
   <xsl:tag-of select="."/> : <xsl:value-of select="."/>
</xsl:for-each>

To get output like this:

name : Robert
profession : programmer
hobby : photography

Of course the above XSLT won't compile because

 <xsl:tag-of select="expression"/>

doesn't exist. But how could this be done?

解决方案

This will give you the current element name (tag name)

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

OP-Edit: This will also do the trick:

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

这篇关于是否有 XSLT name-of 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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