Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Display all node names and values

From: "Neil Smith [MVP Digital Media]" <neil@------.--->
To: NULL
Date: 9/3/2007 10:08:00 PM

On Mon, 3 Sep 2007 09:32:00 -0700, Brent D.
<BrentD@d...> wrote:

>Hello,
>
>Using Asp.Net, does anyone have some sample code that will simply display 
>all of the node names and values in an XML file?  For example:
>
>XML File:


... Should have the processing instruction 
<?xml version="1.0" encoding="utf-8"?>

Your code will problably be failing because you've cut+pasted
"verision" with an extra 'i' after the 'r' in 'version'.


><?xml verision="1.0" encoding="utf-8"?>
><root>
>  <node1>value 1</node1>
>  <list>
>     <node2>value 2</node2>
>     <node3>value 3</node3>
>  </list>
>  <node4>value 4</node4>
></root>
>
>The output would display:
>
>root
>  node1 = value 1
>  list
>     node2 = value 2
>     node3 = value 3
>  node4 = value4


Using this modified identity template will transform the input example
to the desired output, adding approximate tab characters according to
the present node depth (needs some adjustment, it's late here) :


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no" omit-xml-declaration="yes" />

<xsl:param name="node_depth" select="0" />

<xsl:template match="node()|@*">
  <xsl:value-of select="local-name()" />
  <xsl:if test="text() != ''"> = <xsl:value-of select="text()"
/></xsl:if>
  <xsl:text>&#10;</xsl:text>

  <xsl:call-template name="add_tab_stops">
  	<xsl:with-param name="node_depth"
select="count(ancestor::node())" />
  </xsl:call-template>

  <xsl:apply-templates select="node()|@*"/>
</xsl:template>

<xsl:template name="add_tab_stops">
	<xsl:param name="node_depth" />
	<xsl:if test="$node_depth &gt; 0"><xsl:text>&#09;</xsl:text>
		<xsl:call-template name="add_tab_stops">
			<xsl:with-param name="node_depth"
select="$node_depth - 1" />
		</xsl:call-template>
	</xsl:if>
</xsl:template>

</xsl:stylesheet>




HTH
Cheers - Neil



HTH
Cheers - Neil
------------------------------------------------
Digital Media MVP : 2004-2007
http://mvp.support.microsoft.com/mvpfaqs


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent