我是XSLT的新手。我想在我的XSL格式页面中显示XML标签中的所有信息。我尝试使用local-name、name等方法都无法给我想要的结果。
例如:
<step bar="a" bee="localhost" Id="1" Rt="00:00:03" Name="hello">Pass</step>
我希望能够打印出所有信息(例如bar="a"
,bee="localhost"
)以及<step>
元素的值为“Pass”。
我该如何使用xsl实现呢?
谢谢!
//text()|@*
。<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>
有了您的输入,它将产生这个输出:
bar="a"
bee="localhost"
Id="1"
Rt="00:00:03"
Name="hello"
<step> Pass
<xsl:for-each select="attribute::*">
<xsl:value-of select="text()" />
<xsl:value-of select="local-name()" />
</xsl:for-each>
<xsl:value-of select="text()" />
<xsl:value-of select="local-name()" />
value-of
元素没有关闭;这也可能会引起混淆。有点惊讶这个答案在这种情况下得到了赞成。 :-) - Daniel Haley
bar="a"
vsa
) - Daniel Haley