<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flexknowlogy - Jared Stein&#039;s ARCHIVED blog - update to jaredstein.org &#187; tree</title>
	<atom:link href="http://flexknowlogy.learningfield.org/tag/tree/feed/" rel="self" type="application/rss+xml" />
	<link>http://flexknowlogy.learningfield.org</link>
	<description>Jared Stein&#039;s archived blog on education, technology, culture, and the web</description>
	<lastBuildDate>Fri, 30 Oct 2009 19:35:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>XSL to Output Elements, PCDATA, Attributes</title>
		<link>http://flexknowlogy.learningfield.org/2008/10/31/xsl-to-output-elements-pcdata-attributes/</link>
		<comments>http://flexknowlogy.learningfield.org/2008/10/31/xsl-to-output-elements-pcdata-attributes/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 00:58:36 +0000</pubDate>
		<dc:creator>Jared Stein</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[attributes]]></category>
		<category><![CDATA[elements]]></category>
		<category><![CDATA[nodes]]></category>
		<category><![CDATA[tree]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xsl]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://flexknowlogy.learningfield.org/2008/11/06/xsl-to-output-elements-pcdata-attributes/</guid>
		<description><![CDATA[
Tony Hirst was looking for a way to output all XML element names and PCDATA in a document and show hierarchical relationships.  I guessed this was easy, so I tried but initially failed. I searched for an answer and was surprised when I couldn&#8217;t find a good one. An hour later I worked out [...]]]></description>
			<content:encoded><![CDATA[<p>
Tony Hirst was looking for a way to output all XML element names and PCDATA in a document <em>and</em> show hierarchical relationships.  I guessed this was easy, so I tried but initially failed. I searched for an answer and was surprised when I couldn&#8217;t find a good one. An hour later I worked out a solution based on parent::node() that seems stable on all XML files.<span id="more-110"></span> I post it here for future reference:
</p>
<pre>
<code style="width: 100%;font-size: 95%">
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl=
  "http://www.w3.org/1999/XSL/Transform"&gt;
&lt;xsl:output type="xml" /&gt;

&lt;xsl:template match="/"&gt;

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;xsl:for-each select="//*"&gt;&lt;!--loop all levels of nodes--&gt;
   &lt;xsl:if test="position() &gt; 2"&gt;&lt;br/&gt;&lt;/xsl:if&gt;&lt;!--line break after last--&gt;

   &lt;xsl:choose&gt;
      &lt;xsl:when test="*"&gt;&lt;!--does this node have children--&gt;
         &lt;xsl:if test="position() &gt; 1"&gt;
            &lt;!--print node + ancestor relationship--&gt;
            &lt;xsl:value-of select="concat(name(parent::node()),'-&gt;',name())"/&gt;
         &lt;/xsl:if&gt;
      &lt;/xsl:when&gt;

      &lt;xsl:when test=".=text()"&gt;&lt;!--does this node have PCDATA--&gt;
         &lt;!--print node + ancestor relationship--&gt;
         &lt;xsl:value-of select="concat(name(parent::node()),'-&gt;',name())"/&gt;
         &lt;br/&gt;
         &lt;!--print node PCDATA--&gt;
         &lt;xsl:value-of select="concat(name(),'-&gt;','&quot;',text(),'&quot;')"/&gt;
      &lt;/xsl:when&gt;
   &lt;/xsl:choose&gt;

   &lt;xsl:if test="@* &gt; 0"&gt;&lt;!--does this node have attributes--&gt;
      (
      &lt;xsl:for-each select="@*"&gt;&lt;!--for each name/value--&gt;
         &lt;xsl:value-of select="name()"/&gt;
         =
         &lt;xsl:value-of select="."/&gt;

      &lt;/xsl:for-each&gt;
      )
   &lt;/xsl:if&gt;
&lt;/xsl:for-each&gt;

&lt;/body&gt;
&lt;/html&gt;

&lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://flexknowlogy.learningfield.org/2008/10/31/xsl-to-output-elements-pcdata-attributes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
