<?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>output stream &#187; XML &amp; XSL</title>
	<atom:link href="http://duncanandmeg.org/blogs/code/category/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://duncanandmeg.org/blogs/code</link>
	<description>riotous events in amateur development</description>
	<lastBuildDate>Fri, 18 Feb 2011 21:28:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Exporting bibliography from library catalog to XML</title>
		<link>http://duncanandmeg.org/blogs/code/2011/02/08/exporting-bibliography-from-library-catalog-to-xml/</link>
		<comments>http://duncanandmeg.org/blogs/code/2011/02/08/exporting-bibliography-from-library-catalog-to-xml/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 18:58:58 +0000</pubDate>
		<dc:creator>dtjohnso</dc:creator>
				<category><![CDATA[XML & XSL]]></category>

		<guid isPermaLink="false">http://duncanandmeg.org/blogs/code/?p=151</guid>
		<description><![CDATA[As part of a LibGuide project that I was working on recently, I wanted to export the bibliographic data for rare Bibles in our Mack Library collection so that I could generate a list for public viewing. The rare Bibles in our collection are housed in two rooms, the Jerusalem Chamber and Special Collections, and [...]]]></description>
			<content:encoded><![CDATA[<p>As part of a <strike>LibGuide</strike> project that I was working on recently, I wanted to export the bibliographic data for rare Bibles in our Mack Library collection so that I could generate a list for public viewing. The rare Bibles in our collection are housed in two rooms, the Jerusalem Chamber and Special Collections, and because few people ever see the books in Special Collections I thought it would be nice to create a browsable list. Our current library catalog does not make it possible to browse the items in a particular room (or &#8220;location code&#8221; in library science terms).</p>
<p>The process I came up with involves three major components:
<ol>
<li>Finding and exporting the bibliographic records in Millennium using Create Lists</li>
<li>Filtering, finalizing, and structuring the data in Excel 2007</li>
<li>Converting the structured data into clean HTML with XSLT</li>
</ol>
<p>I&#8217;ve posted my files in a <a href="https://github.com/dtjohnso/Millennium-XML-HTML-conversion" class="liexternal">github repo</a> for others to adapt.</p>
<h4>Step 1: Export records from Millennium</h4>
<p>To create my list, I did an item record search based on location code, but stored the bib records in my list.<br />
<a href="http://duncanandmeg.org/blogs/code/wp-content/uploads/2011/02/1.1-millennium-search.png" class="liimagelink"><img src="http://duncanandmeg.org/blogs/code/wp-content/uploads/2011/02/1.1-millennium-search-300x260.png" alt="" title="1.1 millennium search" width="300" height="260" class="alignnone size-medium wp-image-159" /></a></p>
<p>I then exported all the data to text. Because some of the variable-length fields included commas, I used tabs (&#8220;Control character&#8221; 9) as my field delimiter.<br />
<a href="http://duncanandmeg.org/blogs/code/wp-content/uploads/2011/02/1.2-millennium-export.png" class="liimagelink"><img src="http://duncanandmeg.org/blogs/code/wp-content/uploads/2011/02/1.2-millennium-export-267x300.png" alt="" title="1.2 millennium export" width="267" height="300" class="alignnone size-medium wp-image-160" /></a></p>
<h4>Step 2: Manipulation in Excel 2007</h4>
<p>For my situation, data processing in Excel involved a number of small steps. Steps 2.2 and 2.3 may not be necessary for every use case.</p>
<h5>2.1 Import data</h5>
<p>A number of the titles in our collection are not in English, and so I had to specify that the imported data was Unicode (UTF-8). I found out that Excel 2003 does not support importing UTF-8, but Excel 2007 does.</p>
<p><a href="http://duncanandmeg.org/blogs/code/wp-content/uploads/2011/02/2.1-import-unicode.png" class="liimagelink"><img src="http://duncanandmeg.org/blogs/code/wp-content/uploads/2011/02/2.1-import-unicode-300x212.png" alt="" title="2.1 import unicode" width="300" height="212" class="alignnone size-medium wp-image-180" /></a></p>
<p>On step 3 of the import wizard, I set the data format for all columns as &#8220;Text&#8221; rather than &#8220;General&#8221; to avoid any unwanted conversion of my bibliographic data.</p>
<p><a href="http://duncanandmeg.org/blogs/code/wp-content/uploads/2011/02/2.2-import-as-text.png" class="liimagelink"><img src="http://duncanandmeg.org/blogs/code/wp-content/uploads/2011/02/2.2-import-as-text-300x212.png" alt="" title="2.2 import as text" width="300" height="212" class="alignnone size-medium wp-image-181" /></a></p>
<h5>2.2 Filter records (if necessary)</h5>
<p>Because our Special Collections room includes many items besides the Bibles that I was interested in, I needed to filter my data. I did a quick filter for all items with Uniform Titles beginning with &#8220;Bible.&#8221; and used <a href="http://www.lytebyte.com/2008/02/08/how-to-select-and-copy-only-visible-cells-columns-or-rows-in-ms-excel-2007-and-2003/" target="_blank" class="liexternal">Select Visible Cells</a> to copy and paste the data I wanted to a new worksheet to prepare for export.</p>
<h5>2.3 Produce truncated bibID</h5>
<p>The current version of the Innovative Web catalog at my institution does not respond correctly to a full 9 character bibID. Instead, I have to truncate the checkdigit at the end to get a valid link. Now, since that may not make much sense, let me just illustrate:
<ul>
<li><a href="http://library.bju.edu/record=b1184983" class="liexternal">http://library.bju.edu/record=b1184983</a> <b>VALID</b></li>
<li><a href="http://library.bju.edu/record=b11849836" class="liexternal">http://library.bju.edu/record=b11849836</a> &#8211; <b>INVALID</b> (at least, for now)</li>
</ul>
<p>The first example does not include the checkdigit &#8220;6&#8243; at the end. Since the checkdigit is included in the data exported by Millennium, I created a new column at the end of my data and populated it with this Excel formula:</p>
<pre><code class=\'prettyprint\'  class="prettyprint">=LEFT(A2,8)</code></pre>
<p>where &#8220;A2&#8243; is the reference to the cell containing the untruncated bibID.</p>
<h5>2.4 Match columns to XML Schema</h5>
<p>In order to prepare my data for export, I need to match each column to an attribute in a custom XML Schema so I can export structured data that I can meaningfully interpret into HTML.</p>
<p>To do this, I&#8217;ll need to create my schema file, load into Excel, and match each element to the appropriate data columns.</p>
<p>My XSD is as follows, and can be easily adapted to another situation.</p>
<pre><code class=\'prettyprint\'  class="prettyprint">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;schema xmlns="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;element name="Bibliography"&gt;
    &lt;complexType&gt;
      &lt;sequence&gt;
        &lt;element name="Item" maxOccurs="unbounded"&gt;
          &lt;complexType&gt;
            &lt;sequence&gt;
              &lt;element name="ItemTitle" type="string" /&gt;
              &lt;element name="ItemUniformTitle" type="string" /&gt;
              &lt;element name="ItemAuthor" type="string" /&gt;
              &lt;element name="ItemCallNum" type="string" /&gt;
              &lt;element name="ItemEdition" type="string" /&gt;
              &lt;element name="ItemPublication" type="string" /&gt;
              &lt;element name="ItemDescription" type="string" /&gt;
              &lt;element name="ItemSeries" type="string" /&gt;
              &lt;element name="ItemNote" type="string" /&gt;
              &lt;element name="ItemSubject" type="string" /&gt;
              &lt;element name="ItemAddAuthor" type="string" /&gt;
              &lt;element name="ItemAddTitle" type="string" /&gt;
              &lt;element name="ItemISBN" type="string" /&gt;
              &lt;element name="ItemTOC" type="string" /&gt;
              &lt;element name="ItemBibID" type="string" /&gt;
              &lt;element name="ItemBibIDTruncated" type="string" /&gt;
            &lt;/sequence&gt;
          &lt;/complexType&gt;
        &lt;/element&gt;
      &lt;/sequence&gt;
    &lt;/complexType&gt;
  &lt;/element&gt;
&lt;/schema&gt;</code></pre>
<p>Once I have a valid schema, I load it into Excel through XML Source window on the Developer ribbon. To add a new Schema, click the &#8220;XML Maps&#8221; button and then &#8220;Add.&#8221; Then I drag each attribute in the XML tree visible in the XML Source pane and drop it on the appropriate column in my data until the result looks like this:<br />
<a href="http://duncanandmeg.org/blogs/code/wp-content/uploads/2011/02/2.4-XML-source.png" class="liimagelink"><img src="http://duncanandmeg.org/blogs/code/wp-content/uploads/2011/02/2.4-XML-source-300x217.png" alt="" title="2.4 XML source" width="300" height="217" class="alignnone size-medium wp-image-182" /></a></p>
<h5>2.5 Export to XML</h5>
<p>To generate XML from my formatted file, I click the &#8220;Export&#8221; button in the XML section of the Developer ribbon and save to file. Excel will follow my custom schema to produce structured data that I can use to generate HTML output.<br />
<a href="http://duncanandmeg.org/blogs/code/wp-content/uploads/2011/02/2.5-export.png" class="liimagelink"><img src="http://duncanandmeg.org/blogs/code/wp-content/uploads/2011/02/2.5-export-300x206.png" alt="" title="2.5 export" width="300" height="206" class="alignnone size-medium wp-image-183" /></a></p>
<h4>Step 3: Generate HTML with XSLT</h4>
<p>Now that my data is in XML, generating HTML is a simple matter of applying an XSL stylesheet. My stylesheet is as follows:</p>
<pre><code class=\'prettyprint\'  class="prettyprint">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output method="html" indent="no" encoding="UTF-8"/&gt;
  &lt;xsl:template match="/Bibliography"&gt;
    &lt;xsl:apply-templates select="Item"&gt;
      &lt;xsl:sort data-type="text" select="ItemUniformTitle" order="ascending" /&gt;
    &lt;/xsl:apply-templates&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="Item"&gt;
    &lt;p&gt;
      &lt;xsl:variable name="bibID" select="ItemBibIDTruncated"/&gt;
        &lt;xsl:choose&gt;
          &lt;xsl:when test="ItemUniformTitle != ''"&gt;
            <b>&lt;xsl:value-of select="ItemUniformTitle" /&gt;</b>
            &lt;xsl:text&gt; &lt;/xsl:text&gt;
            &lt;xsl:value-of select="ItemTitle"/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
            <b>&lt;xsl:value-of select="ItemTitle"/&gt;</b>
          &lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
        &lt;xsl:text&gt; &lt;/xsl:text&gt;
        &lt;xsl:value-of select="ItemPublication" /&gt;
        &lt;xsl:text&gt; [&lt;/xsl:text&gt;
        <a href="http://library.bju.edu/record={$bibID}" target="_blank">
          &lt;xsl:value-of select="ItemCallNum" /&gt;
        </a>]&lt;xsl:text/&gt;
        &lt;xsl:if test="ItemNote != ''"&gt;
          &lt;br/&gt;
          <i>
            &lt;xsl:value-of select="ItemNote"/&gt;
          </i>
        &lt;/xsl:if&gt;
    &lt;/p&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://duncanandmeg.org/blogs/code/2011/02/08/exporting-bibliography-from-library-catalog-to-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Producing valid RSS from my XSL Transform</title>
		<link>http://duncanandmeg.org/blogs/code/2007/10/11/producing-valid-rss-from-my-xsl-transform/</link>
		<comments>http://duncanandmeg.org/blogs/code/2007/10/11/producing-valid-rss-from-my-xsl-transform/#comments</comments>
		<pubDate>Thu, 11 Oct 2007 21:15:37 +0000</pubDate>
		<dc:creator>dtjohnso</dc:creator>
				<category><![CDATA[XML & XSL]]></category>

		<guid isPermaLink="false">http://duncanandmeg.org/blogs/code/2007/10/11/producing-valid-rss-from-my-xsl-transform/</guid>
		<description><![CDATA[In a previous post, I showed the XSL transform I designed to transform a simple XML file I use into &#8220;(almost) valid RSS.&#8221; I called it (almost) valid because of one problem, which I address here. The problem reviewed My original XSL assigned an arbitrary ID to each entry in the news file based on [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="/blogs/code/2007/08/13/rendering-xml-as-valid-rss-with-xslt/" class="liinternal">a previous post</a>, I showed the XSL transform I designed to transform a simple XML file I use into &#8220;(almost) valid RSS.&#8221; I called it (almost) valid because of one problem, which I address here.</p>
<h2>The problem reviewed</h2>
<p>My original XSL assigned an arbitrary ID to each entry in the news file based on its order in the list. What this meant was that the first item received the integer 1 for an ID, the second 2, the third 3, etc. Here it is:</p>
<pre><code class=\'prettyprint\'  class="prettyprint">&amp;lt;!--old method, produces invalid link &amp; guid--&amp;gt;
&amp;lt;link&amp;gt;&amp;lt;xsl:text&amp;gt;http://www.duncanandmeg.org/news.php#&amp;lt;/xsl:text&amp;gt;
  &amp;lt;xsl:value-of select="position()" /&amp;gt;&amp;lt;/link&amp;gt;
&amp;lt;guid&amp;gt;&amp;lt;xsl:text&amp;gt;http://www.duncanandmeg.org/news.php#&amp;lt;/xsl:text&amp;gt;
  &amp;lt;xsl:value-of select="position()" /&amp;gt;&amp;lt;/guid&amp;gt;</code></pre>
<p>This was fine for my original purposes, but since this hardly represented a unique &#038; permanent identifier for each post, it caused some problems when echoed into the RSS &lt;guid&gt; and &lt;link&gt; elements. The significance of the &lt;guid&gt; element in particular is eliminated with such an approach. Every time I added an item to the list (see the previous post for an explanation of my schema), it would be assigned the ID of 1, and the older posts would be assigned the ID numbers 2, 3, 4, 5 etc.</p>
<p>This meant that most RSS aggregators would not detect that a new post had appeared and would not update accordingly.<br />
<span id="more-8"></span></p>
<h2>Choosing a unique ID schema</h2>
<p>Since I could no longer use my simple numbering scheme based on position in the original XML file, I had to come up with some other identifier. I learned about the <a href="http://www.taguri.org/" class="liexternal">Tag URI algorithm</a>, but decided that it was more complex than I really needed for this application, and the scheme of my original XML file didn&#8217;t lend itself to producing these anyway.</p>
<p>Since I don&#8217;t update the entries in this file frequently, I invented a simple method that produces relatively unique identifiers based on each entry&#8217;s data. All my new ID&#8217;s consist of two elements based on the data in my XML file:</p>
<ol>
<li>The text from the entry&#8217;s title preceding the first space (&#8221; &#8220;) character<br/><i>(If the entry consists of only one word, this element will not appear. This is a weakness that would be more important if updates were frequent)</i></li>
<li>The date of the entry encoded in the format <i>mm-dd-yy</i></li>
</ol>
<p>Once I settled on my scheme, producing it in XSL turned out to be fairly simple.</p>
<h2>XSL transform</h2>
<p>I&#8217;m including only the portion of the XSL tranform that deals with the entry &lt;link&gt; and &lt;guid&gt; here. The rest of it is in <a href="/blogs/code/2007/08/13/rendering-xml-as-valid-rss-with-xslt/" class="liinternal">the previous post</a>.</p>
<pre><code class=\'prettyprint\'  class="prettyprint">&amp;lt;item&amp;gt;
  &amp;lt;title&amp;gt;&amp;lt;xsl:value-of select="headline" /&amp;gt;&amp;lt;/title&amp;gt;

  &amp;lt;!--unique id created and stored in XSL variable--&amp;gt;
  &amp;lt;xsl:variable name="bookmark"&amp;gt;

    &amp;lt;!--find word before first space--&amp;gt;
    &amp;lt;xsl:value-of select="substring-before (headline, ' ')" /&amp;gt;
    &amp;lt;!--produce date in format mm-dd-yy--&amp;gt;
    &amp;lt;xsl:value-of select="translate (date, '/', '-')" /&amp;gt;

  &amp;lt;/xsl:variable&amp;gt;

  &amp;lt;!--variable placed in link and guid elements--&amp;gt;
  &amp;lt;link&amp;gt;&amp;lt;xsl:text&amp;gt;http://www.duncanandmeg.org/news.php#&amp;lt;/xsl:text&amp;gt;
    &amp;lt;xsl:value-of select="$bookmark" /&amp;gt;&amp;lt;/link&amp;gt;
  &amp;lt;guid&amp;gt;&amp;lt;xsl:text&amp;gt;http://www.duncanandmeg.org/news.php#&amp;lt;/xsl:text&amp;gt;
    &amp;lt;xsl:value-of select="$bookmark" /&amp;gt;&amp;lt;/guid&amp;gt;

  &amp;lt;!-- continue with transform, see original post --&amp;gt;

&amp;lt;/item&amp;gt;</code></pre>
<p>With a reasonably unique guid, most RSS readers properly update now when I post new items.</p>
]]></content:encoded>
			<wfw:commentRss>http://duncanandmeg.org/blogs/code/2007/10/11/producing-valid-rss-from-my-xsl-transform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rendering XML as valid RSS with XSLT</title>
		<link>http://duncanandmeg.org/blogs/code/2007/08/13/rendering-xml-as-valid-rss-with-xslt/</link>
		<comments>http://duncanandmeg.org/blogs/code/2007/08/13/rendering-xml-as-valid-rss-with-xslt/#comments</comments>
		<pubDate>Mon, 13 Aug 2007 21:30:02 +0000</pubDate>
		<dc:creator>dtjohnso</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML & XSL]]></category>

		<guid isPermaLink="false">http://duncanandmeg.org/blogs/code/2007/08/13/rendering-xml-as-valid-rss-with-xslt/</guid>
		<description><![CDATA[I&#8217;ve been using a simple XML file to store updates to the main duncanandmeg.org website, and wanted to use XSL to transform that data into a valid RSS feed. This took a little more work than most of my XSL templates to date, so I thought I&#8217;d log the details here. XML data The following [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using a simple XML file to store updates to the <a href="/" class="liinternal">main duncanandmeg.org website</a>, and wanted to use XSL to transform that data into a <a href="http://www.feedvalidator.org/" class="liexternal">valid RSS feed</a>. This took a little more work than most of my XSL templates to date, so I thought I&#8217;d log the details here.<span id="more-5"></span></p>
<h3>XML data</h3>
<p>The following is the structure of my XML file. I&#8217;ve been storing dates in the file in short date format. The detail element is optional, and since is the only element where I embed raw HTML, I encapsulate the contents in CDATA elements.<br />
Also, since I&#8217;m updating this file manually at this point, I add new entries to the top of the file rather than worry about using more automated date sorting.</p>
<pre><code class=\'prettyprint\'  class="prettyprint">&amp;lt;news&amp;gt;
  &amp;lt;entry&amp;gt;
    &amp;lt;headline&amp;gt;headline&amp;lt;/headline&amp;gt;
     &amp;lt;date&amp;gt;mm/dd/yy&amp;lt;/date&amp;gt;
    &amp;lt;detail&amp;gt;&amp;lt;![CDATA[more details (if applicable)]]&amp;gt;&amp;lt;/detail&amp;gt;
  &amp;lt;/entry&amp;gt;
&amp;lt;/news&amp;gt;</code></pre>
<h3>XSL transform</h3>
<p>Because RSS is a more complex standard than my simple XML file, the XSL transform is necessarily complex.</p>
<pre><code class=\'prettyprint\'  class="prettyprint">&amp;lt;xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&amp;gt;

  &amp;lt;xsl:output method="xml"/&amp;gt;

  &amp;lt;xsl:template match="/news"&amp;gt;
  &amp;lt;rss version="2.0"&amp;gt;
    &amp;lt;channel&amp;gt;
      &amp;lt;title&amp;gt;hard-coded title&amp;lt;/title&amp;gt;
      &amp;lt;link&amp;gt;hard-coded url&amp;lt;/link&amp;gt;
      &amp;lt;description&amp;gt;hard-coded description&amp;lt;/description&amp;gt;
      &amp;lt;ttl&amp;gt;60&amp;lt;/ttl&amp;gt;
      &amp;lt;xsl:apply-templates select="entry[position() &amp;lt; 6]" /&amp;gt;
    &amp;lt;/channel&amp;gt;
  &amp;lt;/rss&amp;gt;
  &amp;lt;/xsl:template&amp;gt;

  &amp;lt;xsl:template match="entry"&amp;gt;
    &amp;lt;item&amp;gt;
      &amp;lt;title&amp;gt;&amp;lt;xsl:value-of select="headline" /&amp;gt;&amp;lt;/title&amp;gt;
      &amp;lt;link&amp;gt;&amp;lt;xsl:text&amp;gt;http://www.duncanandmeg.org/news.php#&amp;lt;/xsl:text&amp;gt;
        &amp;lt;xsl:value-of select="position()" /&amp;gt;&amp;lt;/link&amp;gt;
      &amp;lt;guid&amp;gt;&amp;lt;xsl:text&amp;gt;http://www.duncanandmeg.org/news.php#&amp;lt;/xsl:text&amp;gt;
        &amp;lt;xsl:value-of select="position()" /&amp;gt;&amp;lt;/guid&amp;gt;
      &amp;lt;pubDate&amp;gt;&amp;lt;xsl:value-of select="date" /&amp;gt;&amp;lt;/pubDate&amp;gt;
      &amp;lt;description&amp;gt;
        &amp;lt;xsl:if test="detail"&amp;gt;
          &amp;lt;xsl:value-of disable-output-escaping="no" select="detail" /&amp;gt;
        &amp;lt;/xsl:if&amp;gt;
      &amp;lt;/description&amp;gt;
    &amp;lt;/item&amp;gt;
   &amp;lt;/xsl:template&amp;gt;

&amp;lt;/xsl:stylesheet&amp;gt;</code></pre>
<p>This produces <b>almost</b> valid RSS feed for the top 5 items in the feed.</p>
<p>The generated RSS includes dates in short date format (mm/dd/yy), which violates the RSS standard which calls for the <a href="http://feedvalidator.org/docs/error/InvalidRFC2822Date.html" class="liexternal">RFC-822 date-time format</a>. Since all the implementations I could find on the web for doing date conversions in XSL were far too complex for my taste, I proceeded to do that with PHP when I actually transform the XML file into RSS.</p>
<h3>PHP code</h3>
<p>The following PHP represents a minimalist approach to executing the XSL transform and returning RSS as output. This script doesn&#8217;t handle caching, and there are issues with the &lt;link&gt; and &lt;guid&gt; elements in the template for each &lt;entry&gt;.</p>
<p>The consequence of these weaknesses is that some feed readers don&#8217;t properly update when a new post is added to the news.xml file. This is something I&#8217;ll perhaps address in another post.</p>
<pre><code class=\'prettyprint\'  class="prettyprint">&amp;lt;?php
  //Optional. Sets default time zone to something other than GMT
  date_default_timezone_set('EST');

  //Load XML data and transform to RSS
  $xslt = new xsltprocessor;
  $xslt-&gt;importStyleSheet(DomDocument::load('rss.xsl'));
  $xmlResult = $xslt-&gt;transformToXML(DomDocument::load('news.xml'));

  //Load resulting data into the SimpleXML processor
  $xml=simplexml_load_string($xmlResult);

  //Loop through RSS data in SimpleXML
  //Replace each short date with an RFC-822 date-time
  $count = 0;
  foreach($xml-&gt;xpath('//pubDate') as $dates){
    $newDates = date(DATE_RFC822, strtotime($dates));
    $xml-&gt;channel-&gt;item[$count]-&gt;pubDate = $newDates;
    $count++;
  }

  //Optional. These lines insert RFC-822 values
  //for channel/lastBuildDate and channel/pubDate
  $xml-&gt;channel-&gt;addChild("lastBuildDate",$xml-&gt;channel-&gt;item[0]-&gt;pubDate);
  $xml-&gt;channel-&gt;addChild("pubDate",$xml-&gt;channel-&gt;item[0]-&gt;pubDate);

  //Set output content-type to XML
  header('Content-type: application/rss+xml; charset=utf-8');
  print $xml-&gt;asXML(); //Return as XML
?&amp;gt;</code></pre>
<p><!--header('Cache-Control: no-cache');<br />
      header('Pragma: no-cache');--></p>
]]></content:encoded>
			<wfw:commentRss>http://duncanandmeg.org/blogs/code/2007/08/13/rendering-xml-as-valid-rss-with-xslt/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

