开发者

XSLT display ALL XML tag contents

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.

Example:

 <step bar=开发者_如何转开发"a" bee="localhost" Id="1" Rt="00:00:03" Name="hello">Pass</step>

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.

How can I do this with xsl?

Thank you!


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('&lt;',name(parent::*),'> ',.,'&#xA;')"/>
  </xsl:template>

  <xsl:template match="@*">
    <xsl:value-of select="concat(name(),'=&#x22;',.,'&#x22;&#xA;')"/>
  </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


<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()" />   
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜