使用 xslt 遍历属性 [英] Iterating through attributes using xslt

查看:34
本文介绍了使用 xslt 遍历属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 xml 数据,如下所示.

I have an xml data which has shown below.

<Roll NO="4620" CLASSNO="0" ID="0" DID="0" REVSN="0" DNO="3" ></Roll>
<Roll NO="4630" CLASSNO="0" ID="0" DID="0" REVSN="0" DNO="3"></Roll>

我想遍历属性而不使用 XSLT 指定名称.有什么办法吗?

I want to iterate through the attributes without specifying the name using XSLT. Any way to do it?

推荐答案

您可以使用此 XPath @* 获取所有属性,例如:

You can use this XPath @* to get all attributes, e.g.:

XML:

<Roll NO="4620" CLASSNO="0" ID="0" DID="0" REVSN="0" DNO="3"/>

XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/*">
        <xsl:for-each select="@*">
            <xsl:value-of select="concat(name(), ': ', ., ' ')"/>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

输出:

NO: 4620 CLASSNO: 0 ID: 0 DID: 0 REVSN: 0 DNO: 3 

这篇关于使用 xslt 遍历属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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