<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: format code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 12 May 2008 04:18:29 GMT</pubDate>
    <description>DZone Snippets: format code</description>
    <item>
      <title>Output JavaScript variables from PHP</title>
      <link>http://snippets.dzone.com/posts/show/5342</link>
      <description>Class with useful static methods for outputting PHP values into JavaScript format.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com&lt;br /&gt;&lt;br /&gt;class JS{&lt;br /&gt;	//generic and maybe not the desired results xD&lt;br /&gt;	function value($o){&lt;br /&gt;		if($o === null)&lt;br /&gt;			return 'null';&lt;br /&gt;		$t = strtolower(gettype($o));&lt;br /&gt;		if($t == 'string' &amp;&amp; is_numeric($o) &amp;&amp; ($o[0] || strlen($o) == 1) || in_array($t, array('double', 'integer')))&lt;br /&gt;			$t = 'number';&lt;br /&gt;		elseif($t == 'string' &amp;&amp; preg_match('@^\d{4}(?:-\d{1,2}){1,2}(?: (?:\d{1,2}:){2}\d{1,2})?$@', $o)) //strtotime works also with "strange" values strtotime('x')&lt;br /&gt;			$t = 'date';&lt;br /&gt;		elseif($t == 'array' &amp;&amp; ($c = count($k = array_keys($o))) &amp;&amp; $k !== range(0, $c - 1))&lt;br /&gt;			$t = 'object';&lt;br /&gt;		elseif(!in_array($t, array('boolean', 'string', 'array', 'object')))&lt;br /&gt;			$t = 'string';&lt;br /&gt;		$t = 'from' . $t;&lt;br /&gt;		return self::$t($o);&lt;br /&gt;	}&lt;br /&gt;	function fromNumber($o){&lt;br /&gt;		return +$o . '';&lt;br /&gt;	}&lt;br /&gt;	function fromObject($o){&lt;br /&gt;		$r = array();&lt;br /&gt;		foreach($o as $n =&gt; $v)&lt;br /&gt;			$r[] = self::fromString($n) . ':' . self::value($v);&lt;br /&gt;		return '{' . implode(',', $r) . '}';&lt;br /&gt;	}&lt;br /&gt;	function fromBoolean($o){&lt;br /&gt;		return $o ? 'true' : 'false';&lt;br /&gt;	}&lt;br /&gt;	//$q = should quote? &lt;br /&gt;	//$c = char that will be used to quote&lt;br /&gt;	function fromString($o, $q = true, $c = '"'){&lt;br /&gt;		return ($p = $q ? $c : '') . preg_replace('/\r\n|\n\r|\r/', '\n', str_replace($c, '\\' . $c, str_replace('\\', '\\\\', $o))) . $p;&lt;br /&gt;	}&lt;br /&gt;	function fromArray($o){&lt;br /&gt;		$s = '';&lt;br /&gt;		foreach($o as $v)&lt;br /&gt;			$s .= ($s ? ',' : '') . self::value($v);&lt;br /&gt;		return '[' . $s . ']';&lt;br /&gt;	}&lt;br /&gt;	function fromDate($o){&lt;br /&gt;		(is_numeric($o) &amp;&amp; $o = +$o) || ($o = strtotime($o)) &gt; 0 || ($o = mktime());&lt;br /&gt;		$o = explode(',', date('Y,n,j,G,i,s', $o));&lt;br /&gt;		foreach($o as $i =&gt; $v)&lt;br /&gt;			$o[$i] = +$v;&lt;br /&gt;		return 'new Date(' . implode(',', $o)  . ')';&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Example&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$o = new stdClass;&lt;br /&gt;$o-&gt;abc = 123;&lt;br /&gt;echo implode("\n&lt;br /&gt;", array(&lt;br /&gt;	JS::value('1984-07-22 11:30:12'),&lt;br /&gt;	JS::value('Test'),&lt;br /&gt;	JS::value(1234),&lt;br /&gt;	JS::value(true),&lt;br /&gt;	JS::value(array(1,2,3)),&lt;br /&gt;	JS::value(array('lala' =&gt; 'x')),&lt;br /&gt;	JS::value($o)&lt;br /&gt;));&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 09 Apr 2008 23:57:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5342</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
    <item>
      <title>Rails Date Formats</title>
      <link>http://snippets.dzone.com/posts/show/5231</link>
      <description>// cribbed from http://wiki.rubyonrails.org/rails/pages/HowToDefineYourOwnDateFormat&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;my_formats = {&lt;br /&gt;  :my_format_1 =&gt; '%l %p, %b %d, %Y',&lt;br /&gt;  :my_format_2  =&gt; '%l:%M %p, %B %d, %Y'&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(my_formats)&lt;br /&gt;ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(my_formats)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 14 Mar 2008 14:32:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5231</guid>
      <author>willcodeforfoo ()</author>
    </item>
    <item>
      <title>Calculate last day of current Month</title>
      <link>http://snippets.dzone.com/posts/show/5183</link>
      <description>'Determines what the next month is based on today and subtracts 1 day from first day of next month. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;'VB.NET&lt;br /&gt;Dim NextMonth As Integer&lt;br /&gt;Dim RptYear As Integer&lt;br /&gt;'Determine next month&lt;br /&gt;NextMonth = DatePart(DateInterval.Month, DateAdd(DateInterval.Month, +1, today))&lt;br /&gt;'Determine the year of the next month, in case you are going from Dec to Jan&lt;br /&gt;RptYear = DatePart(DateInterval.Year, DateAdd(DateInterval.Month, +1, today))&lt;br /&gt;'Subtract 1 day from the first day of next month to get this months last day&lt;br /&gt;Return DateAdd(DateInterval.Day, -1, DateValue(NextMonth.ToString &amp; "/1/" &amp; RptYear.ToString))&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 27 Feb 2008 19:13:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5183</guid>
      <author>bmowbray (Brian Mowbray)</author>
    </item>
    <item>
      <title>Format Ruby code in HTML</title>
      <link>http://snippets.dzone.com/posts/show/5178</link>
      <description>This code uses the Ruby gem 'syntax' to create an XML file containing the HTML tags around the code, which is then transformed into an HTML file. The working example was first built using coding examples from &lt;a href="http://blog.wolfman.com/articles/2006/05/26/howto-format-ruby-code-for-blogs"&gt;Howto format ruby code for blogs&lt;/a&gt; [wolfman.com] and &lt;a href="http://brentrubyrails.blogspot.com/2007/12/formatting-ruby-and-html-code-for-blog.html"&gt;Formatting Ruby and HTML code for blog posting&lt;/a&gt; [blogspot.com]&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/ruby&lt;br /&gt;&lt;br /&gt;#file: ruby2html.rb &lt;br /&gt;&lt;br /&gt;require 'rubygems'&lt;br /&gt;require 'syntax/convertors/html'&lt;br /&gt;require 'projxslt' # &lt;- this is my own class to do an XSLT transform &lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;class Ruby2Html&lt;br /&gt;  def initialize(rubyfile, htmlfile)&lt;br /&gt;    code = File.read(rubyfile)&lt;br /&gt;    convertor = Syntax::Convertors::HTML.for_syntax "ruby"&lt;br /&gt;    code_html = convertor.convert(code)&lt;br /&gt;    &lt;br /&gt;    tempfile = '../temp/ruby2html.xml'&lt;br /&gt;    xslfile = '../ruby2html/ruby2html.xsl'&lt;br /&gt;    save_file(tempfile, code_html)&lt;br /&gt;    &lt;br /&gt;    px = Projxslt.new(tempfile, xslfile)&lt;br /&gt;    buffer = px.transform()&lt;br /&gt;    save_file(htmlfile, buffer)&lt;br /&gt;    &lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  def save_file(filename, buffer)&lt;br /&gt;    file = File.new(filename, 'w')&lt;br /&gt;    file.puts buffer&lt;br /&gt;    file.close&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;if __FILE__ == $0&lt;br /&gt;  r2h = Ruby2Html.new('ruby2html.rb', '../temp/ruby2html.html')&lt;br /&gt;  puts 'completed'&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;file: ruby2html.xsl&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&lt;br /&gt;                xmlns="http://www.w3.org/1999/xhtml"&lt;br /&gt;                version="1.0"&gt;&lt;br /&gt;&lt;br /&gt;  &lt;xsl:output method="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;br /&gt;          doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;br /&gt;          encoding="ISO-8859-1"/&gt; &lt;br /&gt;&lt;br /&gt;	&lt;xsl:template match="/"&gt;&lt;br /&gt;	&lt;xsl:element name="html"&gt;&lt;br /&gt;&lt;br /&gt;        &lt;head&gt;&lt;br /&gt;          &lt;title&gt;Sample code&lt;/title&gt;&lt;br /&gt;          &lt;link rel="stylesheet" type="text/css" href="ruby2html.css" /&gt;&lt;br /&gt;	&lt;/head&gt;&lt;br /&gt;&lt;br /&gt;	&lt;body&gt;&lt;br /&gt;          &lt;div id="wrap"&gt;&lt;br /&gt;          &lt;xsl:apply-templates /&gt;&lt;br /&gt;          &lt;/div&gt;&lt;br /&gt;	&lt;/body&gt; &lt;br /&gt;&lt;br /&gt;	&lt;/xsl:element&gt;&lt;br /&gt;	&lt;/xsl:template&gt;&lt;br /&gt;&lt;br /&gt;	&lt;xsl:template match="pre"&gt;&lt;br /&gt;	  &lt;xsl:copy-of select="."/&gt;&lt;br /&gt;	&lt;/xsl:template&gt;&lt;br /&gt;&lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here's the output from the &lt;a href="http://www.twitxr.com/image/7628/"&gt;formatted Ruby HTML code&lt;/a&gt; [twitxr.com]&lt;br /&gt;&lt;br /&gt;Referemce: &lt;a href="http://syntax.rubyforge.org/"&gt;Syntax Manual&lt;/a&gt; [rubyforge.org]</description>
      <pubDate>Tue, 26 Feb 2008 15:43:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5178</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Formatting a date in XSLT</title>
      <link>http://snippets.dzone.com/posts/show/5118</link>
      <description>This template formats a date ie 060208171320 -&gt; 06-Feb-08T17:13:20&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  &lt;xsl:template name="FormatDate"&gt;&lt;br /&gt;    &lt;xsl:param name="DateTime" /&gt;&lt;br /&gt;    &lt;!-- new date format 2006-01-14T08:55:22 --&gt;&lt;br /&gt;    &lt;xsl:variable name="mo"&gt;&lt;br /&gt;      &lt;xsl:value-of select="substring($DateTime,3,2)" /&gt;&lt;br /&gt;    &lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="day"&gt;&lt;br /&gt;      &lt;xsl:value-of select="substring($DateTime,5,2)" /&gt;&lt;br /&gt;    &lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="year"&gt;&lt;br /&gt;      &lt;xsl:value-of select="substring($DateTime,1,2)" /&gt;&lt;br /&gt;    &lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="hh"&gt;&lt;br /&gt;      &lt;xsl:value-of select="substring($DateTime,7,2)" /&gt;&lt;br /&gt;    &lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="mm"&gt;&lt;br /&gt;      &lt;xsl:value-of select="substring($DateTime,9,2)" /&gt;&lt;br /&gt;    &lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="ss"&gt;&lt;br /&gt;      &lt;xsl:value-of select="substring($DateTime,11,2)" /&gt;&lt;br /&gt;    &lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:if test="(string-length($day) &amp;lt; 2)"&gt;&lt;br /&gt;      &lt;xsl:value-of select="0"/&gt;&lt;br /&gt;    &lt;/xsl:if&gt;&lt;br /&gt;    &lt;xsl:value-of select="$day"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="'-'"/&gt;&lt;br /&gt;    &lt;xsl:choose&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '01'"&gt;Jan&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '02'"&gt;Feb&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '03'"&gt;Mar&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '04'"&gt;Apr&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '05'"&gt;May&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '06'"&gt;Jun&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '07'"&gt;Jul&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '08'"&gt;Aug&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '09'"&gt;Sep&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '10'"&gt;Oct&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '11'"&gt;Nov&lt;/xsl:when&gt;&lt;br /&gt;      &lt;xsl:when test="$mo = '12'"&gt;Dec&lt;/xsl:when&gt;&lt;br /&gt;    &lt;/xsl:choose&gt;&lt;br /&gt;    &lt;xsl:value-of select="'-'"/&gt;&lt;br /&gt;&lt;br /&gt;    &lt;xsl:value-of select="$year"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="'T'"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="$hh"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="':'"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="$mm"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="':'"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="$ss"/&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;copied from http://snipr.com/1z833 [geekswithblogs.net] and modified to suit the date input format I used.</description>
      <pubDate>Fri, 08 Feb 2008 00:00:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5118</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Pretty Print XML using Ruby</title>
      <link>http://snippets.dzone.com/posts/show/4953</link>
      <description>This code makes the XML output look pretty.  I tried using the documentation from the REXML website to apply the method example doc.write($stdout,0), but I gave up, and instead wrote my own XML pretty-print method.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;  def pretty_print(parent_node, itab)&lt;br /&gt;    buffer = ''&lt;br /&gt;&lt;br /&gt;    parent_node.elements.each do |node|&lt;br /&gt;&lt;br /&gt;      buffer += ' ' * itab + "&lt;#{node.name}#{get_att_list(node)}"&lt;br /&gt;  &lt;br /&gt;      if node.to_a.length &gt; 0&lt;br /&gt;        buffer += "&gt;"&lt;br /&gt;        if node.text.nil?&lt;br /&gt;          buffer += "\n"&lt;br /&gt;          buffer += pretty_print(node,itab+2) &lt;br /&gt;          buffer += ' ' * itab + "&lt;/#{node.name}&gt;\n"&lt;br /&gt;        else&lt;br /&gt;          node_text = node.text.strip&lt;br /&gt;          if node_text != ''&lt;br /&gt;            buffer += node_text &lt;br /&gt;            buffer += "&lt;/#{node.name}&gt;\n"        &lt;br /&gt;          else&lt;br /&gt;            buffer += "\n" + pretty_print(node,itab+2) &lt;br /&gt;            buffer += ' ' * itab + "&lt;/#{node.name}&gt;\n"        &lt;br /&gt;          end&lt;br /&gt;        end&lt;br /&gt;      else&lt;br /&gt;        buffer += "/&gt;\n"&lt;br /&gt;      end&lt;br /&gt;      &lt;br /&gt;    end&lt;br /&gt;    buffer&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def get_att_list(node)&lt;br /&gt;    att_list = ''&lt;br /&gt;    node.attributes.each { |attribute, val| att_list += " #{attribute}='#{val}'" }&lt;br /&gt;    att_list&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  def pretty_xml(doc)&lt;br /&gt;    buffer = ''&lt;br /&gt;    xml_declaration = doc.to_s.match('&lt;\?.*\?&gt;').to_s&lt;br /&gt;    buffer += "#{xml_declaration}\n" if not xml_declaration.nil?&lt;br /&gt;    xml_doctype = doc.to_s.match('&lt;\!.*\"&gt;').to_s&lt;br /&gt;    buffer += "#{xml_doctype}\n" if not xml_doctype.nil?&lt;br /&gt;    buffer += "&lt;#{doc.root.name}#{get_att_list(doc.root)}"&lt;br /&gt;    if doc.root.to_a.length &gt; 0&lt;br /&gt;      buffer +="&gt;\n#{pretty_print(doc.root,2)}&lt;/#{doc.root.name}&gt;"&lt;br /&gt;    else&lt;br /&gt;      buffer += "/&gt;\n"&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;xml_data = "&lt;hi id='124'&gt;&lt;yo&gt;&lt;a id='1'/&gt;&lt;b/&gt;&lt;c/&gt;&lt;/yo&gt;&lt;sushi&gt;&lt;love&gt;Ruby&lt;/love&gt;&lt;/sushi&gt;&lt;/hi&gt;"&lt;br /&gt;doc = Document.new(xml_data)&lt;br /&gt;pretty_xml(doc)&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;output&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;hi id='124'&gt;&lt;br /&gt;  &lt;yo&gt;&lt;br /&gt;    &lt;a id='1'/&gt;&lt;br /&gt;    &lt;b/&gt;&lt;br /&gt;    &lt;c/&gt;&lt;br /&gt;  &lt;/yo&gt;&lt;br /&gt;  &lt;sushi&gt;&lt;br /&gt;    &lt;love&gt;Ruby&lt;/love&gt;&lt;br /&gt;  &lt;/sushi&gt;&lt;br /&gt;&lt;/hi&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;*Update 7-Jan-08 1:51AM *&lt;br /&gt;Although I haven't tried running the following XSL code, this might actually have been a better solution to my problem. source: http://www.printk.net/~bds/indent.html&lt;br /&gt;&lt;br /&gt;*Pretty Print XML using XSLT*&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;&lt;br /&gt;  &lt;xsl:output method="xml" encoding="ISO-8859-1"/&gt;&lt;br /&gt;  &lt;xsl:param name="indent-increment" select="'   '"/&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;xsl:template name="newline"&gt;&lt;br /&gt;    &lt;xsl:text disable-output-escaping="yes"&gt;&lt;br /&gt;&lt;/xsl:text&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;xsl:template match="comment() | processing-instruction()"&gt;&lt;br /&gt;    &lt;xsl:param name="indent" select="''"/&gt;&lt;br /&gt;    &lt;xsl:call-template name="newline"/&gt;    &lt;br /&gt;    &lt;xsl:value-of select="$indent"/&gt;&lt;br /&gt;    &lt;xsl:copy /&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;xsl:template match="text()"&gt;&lt;br /&gt;    &lt;xsl:param name="indent" select="''"/&gt;&lt;br /&gt;    &lt;xsl:call-template name="newline"/&gt;    &lt;br /&gt;    &lt;xsl:value-of select="$indent"/&gt;&lt;br /&gt;    &lt;xsl:value-of select="normalize-space(.)"/&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;    &lt;br /&gt;  &lt;xsl:template match="text()[normalize-space(.)='']"/&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;xsl:template match="*"&gt;&lt;br /&gt;    &lt;xsl:param name="indent" select="''"/&gt;&lt;br /&gt;    &lt;xsl:call-template name="newline"/&gt;    &lt;br /&gt;    &lt;xsl:value-of select="$indent"/&gt;&lt;br /&gt;      &lt;xsl:choose&gt;&lt;br /&gt;       &lt;xsl:when test="count(child::*) &gt; 0"&gt;&lt;br /&gt;        &lt;xsl:copy&gt;&lt;br /&gt;         &lt;xsl:copy-of select="@*"/&gt;&lt;br /&gt;         &lt;xsl:apply-templates select="*|text()"&gt;&lt;br /&gt;           &lt;xsl:with-param name="indent" select="concat ($indent, $indent-increment)"/&gt;&lt;br /&gt;         &lt;/xsl:apply-templates&gt;&lt;br /&gt;         &lt;xsl:call-template name="newline"/&gt;&lt;br /&gt;         &lt;xsl:value-of select="$indent"/&gt;&lt;br /&gt;        &lt;/xsl:copy&gt;&lt;br /&gt;       &lt;/xsl:when&gt;       &lt;br /&gt;       &lt;xsl:otherwise&gt;&lt;br /&gt;        &lt;xsl:copy-of select="."/&gt;&lt;br /&gt;       &lt;/xsl:otherwise&gt;&lt;br /&gt;     &lt;/xsl:choose&gt;&lt;br /&gt;  &lt;/xsl:template&gt;    &lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 07 Jan 2008 01:41:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4953</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Simple output of date in perl</title>
      <link>http://snippets.dzone.com/posts/show/4506</link>
      <description>// Simple output of current date in perl&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  my @day_name = ("Sun.","Mon.","Tue.","Wed.","Thu.","Fri.","Sat.");&lt;br /&gt;  my ($sec,$min,$hour,$mday,$mon,$year,$wday); &lt;br /&gt;  ($sec,$min,$hour,$mday,$mon,$year,$wday,undef,undef)=localtime(time()); $year+=1900;$mon++;&lt;br /&gt;  $report_date=sprintf("%s %04d.%02d.%02d %02d:%02d",$day_name[$wday],$year,$mon,$mday,$hour,$min);&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 07 Sep 2007 07:55:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4506</guid>
      <author>bouffon69 (Sylvain Le Courtois)</author>
    </item>
    <item>
      <title>RecordSet to tab-separated values</title>
      <link>http://snippets.dzone.com/posts/show/3644</link>
      <description>&lt;code&gt;&lt;br /&gt;Function TSV(rs)&lt;br /&gt;	Dim field&lt;br /&gt;	For Each field In rs.Fields&lt;br /&gt;		TSV = TSV &amp; field.Name &amp; VBTab&lt;br /&gt;	Next&lt;br /&gt;	TSV = Left(TSV, Len(TSV) - 1) &amp; vbCr &amp; rs.GetString()&lt;br /&gt;End Function&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The rows are separated by vbCr ("\r" in most languages).&lt;br /&gt;The first row is the field names.</description>
      <pubDate>Wed, 07 Mar 2007 21:51:49 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3644</guid>
      <author>mrclay (Steve Clay)</author>
    </item>
    <item>
      <title>Actionscript _Text Class</title>
      <link>http://snippets.dzone.com/posts/show/3517</link>
      <description>Useful functions for adding dynamic text fields.  Don't forget, you have to add the font of choice into the main movie Library for this to work (Library Panel Menu &gt; New Font).  The name you give the font is the string that you pass to the getTextFormat function for the "font" parameter.  Setup your font styles with getTextFormat, setup your dynamic text box with getTextField, and then add text to the text box with appendTextField.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;dynamic class _Text {&lt;br /&gt;	static function getTextFormat(font:String,size:Number,color:Number,leading:Number,url:String,target:String){&lt;br /&gt;		var fmt:TextFormat = new TextFormat();&lt;br /&gt;		fmt.font = font;&lt;br /&gt;		fmt.kerning = true;&lt;br /&gt;		fmt.leading = (leading != undefined &amp;&amp; leading != null) ? leading : 0;&lt;br /&gt;		fmt.bold = false;&lt;br /&gt;		fmt.size = (size != undefined &amp;&amp; size != null) ? size : 11;&lt;br /&gt;		fmt.color = (color != undefined &amp;&amp; color != null) ? color : 0x000000;&lt;br /&gt;&lt;br /&gt;		if (url != undefined &amp;&amp; url != null) {&lt;br /&gt;			fmt.url = url;&lt;br /&gt;			fmt.target = (target != undefined &amp;&amp; target != null) ? target : "_self";&lt;br /&gt;		}&lt;br /&gt;		return (fmt);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	static function getTextField(targetMC,targetDepth,txtFieldName,x,y,w,h,txtObj){&lt;br /&gt;		var targetDepth = (targetDepth != undefined &amp;&amp; targetDepth != null) ? targetDepth : targetMC.getNextHighestDepth();&lt;br /&gt;		var txtfld = targetMC.createTextField(txtFieldName, targetDepth, x, y, w, h);&lt;br /&gt;		txtfld.antiAliasType = (txtObj.antiAliasType) ? txtObj.antiAliasType : "advanced";&lt;br /&gt;		txtfld.sharpness = (txtObj.sharpness) ? txtObj.sharpness : -60;&lt;br /&gt;		txtfld.thickness = (txtObj.thickness) ? txtObj.thickness : -100;&lt;br /&gt;		txtfld.embedFonts = (txtObj.embedFonts) ? txtObj.embedFonts : true;&lt;br /&gt;		txtfld.selectable = (txtObj.selectable) ? txtObj.selectable : false;&lt;br /&gt;		txtfld.html = (txtObj.html) ? txtObj.html : true;&lt;br /&gt;		txtfld.multiline = (txtObj.multiline) ? txtObj.multiline : true;&lt;br /&gt;		txtfld.autoSize = (txtObj.autoSize) ? txtObj.autoSize : "left";&lt;br /&gt;		&lt;br /&gt;		if (txtObj.htmlText) txtfld.htmlText = txtObj.htmlText;&lt;br /&gt;		if (txtObj.txtFormat) txtfld.setTextFormat(txtObj.txtFormat);&lt;br /&gt;		&lt;br /&gt;		if (txtObj.wordWrap == undefined || txtObj.wordWrap == null) txtfld._width = txtfld.textWidth + 10;&lt;br /&gt;		else txtfld.wordWrap = txtObj.wordWrap;&lt;br /&gt;		return txtfld;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	static function appendTextField(txtfld,txtfrmt,txt){&lt;br /&gt;		var beginIndex:Number = txtfld.htmlText.length;&lt;br /&gt;		txtfld.setNewTextFormat(txtfrmt);&lt;br /&gt;		txtfld.replaceText(beginIndex,beginIndex,txt);&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 13 Feb 2007 20:17:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3517</guid>
      <author>bgidge (Bryan Gidge)</author>
    </item>
    <item>
      <title>Objective-C and Cocoa: Human-readable file size from number of bytes</title>
      <link>http://snippets.dzone.com/posts/show/3038</link>
      <description>// Returns a human-readable string showing the file size from the number of bytes&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;- (NSString *)stringFromFileSize:(int)theSize&lt;br /&gt;{&lt;br /&gt;	float floatSize = theSize;&lt;br /&gt;	if (theSize&lt;1023)&lt;br /&gt;		return([NSString stringWithFormat:@"%i bytes",theSize]);&lt;br /&gt;	floatSize = floatSize / 1024;&lt;br /&gt;	if (floatSize&lt;1023)&lt;br /&gt;		return([NSString stringWithFormat:@"%1.1f KB",floatSize]);&lt;br /&gt;	floatSize = floatSize / 1024;&lt;br /&gt;	if (floatSize&lt;1023)&lt;br /&gt;		return([NSString stringWithFormat:@"%1.1f MB",floatSize]);&lt;br /&gt;	floatSize = floatSize / 1024;&lt;br /&gt;&lt;br /&gt;	// Add as many as you like&lt;br /&gt;&lt;br /&gt;	return([NSString stringWithFormat:@"%1.1f GB",floatSize]);&lt;br /&gt;}&lt;/code&gt;</description>
      <pubDate>Sun, 26 Nov 2006 05:51:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3038</guid>
      <author>maximile (Max Williams)</author>
    </item>
  </channel>
</rss>
