XSLT displays the contents of an entire XML tag

I am new to using XSLT. I want to display all the information in an xml tag on my formatted xsl page. I tried using local-name, name, etc., and no one gives 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 all the information ( bar="a" , bee="localhost" ), etc., as well as the value of <step> Pass.

How to do this using xsl?

Thanks!

+4
source share
2 answers

If you want to return only values, you can use XPath //text()|@* .

If you want attribute and element names along with values, you can 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
source
 <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()" /> 
+2
source

All Articles