XSLT display ALL XML tag contents

2020-04-08 12:12发布

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!

标签: xml xslt nodes
2条回答
Rolldiameter
2楼-- · 2020-04-08 12:51

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
查看更多
手持菜刀,她持情操
3楼-- · 2020-04-08 13:00
<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()" />   
查看更多
登录 后发表回答