XSLT 显示所有 XML 标签内容 [英] XSLT display ALL XML tag contents
问题描述
我是 XSLT 的新手.我想在我的 xsl 格式页面的 xml 标记中显示所有信息.我曾尝试使用本地名称、名称等,但都没有给我想要的结果.
I am new to using XSLT. I want to display all of the information in an xml tag in my xsl formatted page. I have tried using local-name, name, etc and none give me the result I want.
示例:
<step bar="a" bee="localhost" Id="1" Rt="00:00:03" Name="hello">Pass</step>
我希望能够打印出所有信息(bar="a"
、bee="localhost"
)等以及
通过.
I would like to be able to print out all of the information (bar="a"
, bee="localhost"
) etc as well as the value of <step>
Pass.
如何使用 xsl 执行此操作?
How can I do this with xsl?
谢谢!
推荐答案
如果只想返回值,可以使用 XPath //text()|@*
.
If you want to return just the values, you could use the XPath //text()|@*
.
如果你想要属性/元素名称和值,你可以使用这个样式表:
If you want the attribute/element names along with the values, you could use this stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:apply-templates select="node()|@*"/>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="concat('<',name(parent::*),'> ',.,'
')"/>
</xsl:template>
<xsl:template match="@*">
<xsl:value-of select="concat(name(),'="',.,'"
')"/>
</xsl:template>
</xsl:stylesheet>
根据您的输入,它将产生以下输出:
With your input, it will produce this output:
bar="a"
bee="localhost"
Id="1"
Rt="00:00:03"
Name="hello"
<step> Pass
这篇关于XSLT 显示所有 XML 标签内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!