<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: xslt code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 20:38:27 GMT</pubDate>
    <description>DZone Snippets: xslt code</description>
    <item>
      <title>Using the XSLT function document()</title>
      <link>http://snippets.dzone.com/posts/show/5683</link>
      <description>I found an  XSLT solution recently using the built-in function document() to include an additional XML document into the current XML document.&lt;br /&gt;&lt;br /&gt;Using the file lunch.xml with drink.xml I can show what is available for today's lunch menu.&lt;br /&gt;&lt;br /&gt;file: lunch.xml&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;food&gt;&lt;br /&gt;  &lt;item name="banana"/&gt;&lt;br /&gt;  &lt;item name="apple"/&gt;&lt;br /&gt;  &lt;item name="custard"/&gt;&lt;br /&gt;  &lt;item name="crisps"/&gt;&lt;br /&gt;&lt;/food&gt;  &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;file: drink.xml&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;drinks&gt;&lt;br /&gt;  &lt;drink name="water"/&gt;&lt;br /&gt;  &lt;drink name="orange"/&gt;&lt;br /&gt;  &lt;drink name="lemonade"/&gt;&lt;br /&gt;  &lt;drink name="cream soda"/&gt;&lt;br /&gt;  &lt;drink name="tea"/&gt;&lt;br /&gt;  &lt;drink name="coffee"/&gt;&lt;br /&gt;  &lt;drink name="blackcurrant juice"/&gt;&lt;br /&gt;  &lt;drink name="ginger ale with lime"/&gt;&lt;br /&gt;&lt;/drinks&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;file: lunch.xsl&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:template match="food"&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;  &lt;head&gt;&lt;title&gt;Food menu&lt;/title&gt;&lt;/head&gt;&lt;br /&gt;  &lt;body&gt;&lt;br /&gt;  &lt;h1&gt;To eat&lt;/h1&gt;&lt;br /&gt;  &lt;ul&gt;&lt;br /&gt;  &lt;xsl:apply-templates select="item" /&gt;&lt;br /&gt;  &lt;/ul&gt;&lt;br /&gt;  &lt;h1&gt;To drink&lt;/h1&gt;&lt;br /&gt;  &lt;xsl:value-of select="document('drink.xml')/drinks/drink[2]/@name"/&gt;&lt;br /&gt;  &lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;         &lt;br /&gt;&lt;/xsl:template&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:template match="item"&gt;&lt;br /&gt;  &lt;li&gt;&lt;xsl:value-of select="@name"/&gt;&lt;/li&gt;&lt;br /&gt;&lt;/xsl:template&gt;&lt;br /&gt;&lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;output:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;html&gt;&lt;body&gt;&lt;br /&gt;&lt;h1&gt;To eat&lt;/h1&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;banana&lt;/li&gt;&lt;br /&gt;&lt;li&gt;apple&lt;/li&gt;&lt;br /&gt;&lt;li&gt;custard&lt;/li&gt;&lt;br /&gt;&lt;li&gt;crisps&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h1&gt;To drink&lt;/h1&gt;orange&lt;/body&gt;&lt;/html&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 24 Jun 2008 14:09:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5683</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Quick-Prototype POJO with camelCase using XSLT</title>
      <link>http://snippets.dzone.com/posts/show/5682</link>
      <description>// If you've ever been frustrated trying to write an enormous POJO, here's a way to speed the &lt;br /&gt;// process a little. It's far from perfect, and could use some tweaking, but this XSLT code will &lt;br /&gt;// spit out a POJO much faster than you could do it by hand.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;TableDDLs.xml&lt;br /&gt;&lt;schema&gt;&lt;br /&gt;	&lt;table name="tlkpDepartment"&gt;&lt;br /&gt;        &lt;columns&gt;&lt;br /&gt;            &lt;column name="DeptCode" type="integer" null="no" primarykey="yes" /&gt;&lt;br /&gt;            &lt;column name="DeptDesc" type="varchar"&lt;br /&gt;                size="30" null="yes" /&gt;&lt;br /&gt;            &lt;column name="Active" type="integer" null="no" /&gt;&lt;br /&gt;        &lt;/columns&gt;&lt;br /&gt;	&lt;table name="tblAddress"&gt;&lt;br /&gt;		&lt;columns&gt;&lt;br /&gt;			&lt;column name="AddressID" type="integer" null="no" /&gt;&lt;br /&gt;			&lt;column name="Address1" type="varchar" size="150" null="no" /&gt;&lt;br /&gt;			&lt;column name="Address2" type="varchar" size="150" null="no" /&gt;&lt;br /&gt;			&lt;column name="City" type="varchar" size="50" null="no" /&gt;&lt;br /&gt;			&lt;column name="State" type="varchar" size="2" null="yes" /&gt;&lt;br /&gt;			&lt;column name="ZipCode" type="varchar" size="10" null="no" /&gt;&lt;br /&gt;		&lt;/columns&gt;&lt;br /&gt;	&lt;/table&gt;&lt;br /&gt;&lt;/schema&gt;&lt;br /&gt;&lt;br /&gt;CreatePOJOs.xsl&lt;br /&gt;&lt;?xml version="1.0" encoding="iso-8859-1"?&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 encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/&gt;&lt;br /&gt;    &lt;br /&gt;&lt;xsl:variable name="lcletters"&gt;abcdefghijklmnopqrstuvwxyz&lt;/xsl:variable&gt;&lt;br /&gt;&lt;xsl:variable name="ucletters"&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/xsl:variable&gt;&lt;br /&gt;&lt;br /&gt;  &lt;!-- pass the document's children to our converter --&gt;&lt;br /&gt;  &lt;xsl:template match="/"&gt;&lt;br /&gt;    &lt;xsl:call-template name="createPojo"&gt;&lt;br /&gt;    &lt;/xsl:call-template&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;	&lt;br /&gt;&lt;xsl:template name="createPojo"&gt;&lt;br /&gt;	&lt;xsl:for-each select="/schema/table"&gt;&lt;br /&gt;/**&lt;br /&gt; *   &lt;xsl:value-of select="@name" /&gt;  example of POJO output&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;	&lt;br /&gt;package pojo;&lt;br /&gt;	&lt;br /&gt;import java.sql.Date;&lt;br /&gt;	&lt;br /&gt;/**&lt;br /&gt; * @author [your name here]&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;public class &lt;xsl:value-of select="@name" /&gt; {&lt;br /&gt;		&lt;xsl:for-each select="columns/column"&gt;&lt;br /&gt;			&lt;xsl:variable name="datatype" select="@type" /&gt;&lt;br /&gt;			&lt;xsl:variable name="columnName" select="@name" /&gt;&lt;br /&gt;    private &lt;xsl:choose&gt;&lt;xsl:when test="$datatype='integer'"&gt; Long &lt;/xsl:when&gt;&lt;xsl:when test="$datatype='varchar'"&gt; String &lt;/xsl:when&gt;&lt;xsl:when test="$datatype='date'"&gt; Date &lt;/xsl:when&gt;&lt;/xsl:choose&gt; &lt;xsl:call-template name="camelCaseTheColumn"&gt;&lt;xsl:with-param name="column" select="$columnName" /&gt;&lt;/xsl:call-template&gt; = null;&lt;/xsl:for-each&gt;&lt;br /&gt;		&lt;xsl:for-each select="columns/column"&gt;&lt;br /&gt;			&lt;xsl:variable name="datatype" select="@type" /&gt;&lt;br /&gt;            &lt;xsl:variable name="columnName" select="@name" /&gt;&lt;br /&gt;    public&lt;xsl:choose&gt;&lt;xsl:when test="$datatype='integer'"&gt; Long &lt;/xsl:when&gt;&lt;xsl:when test="$datatype='varchar'"&gt; String&lt;/xsl:when&gt;&lt;xsl:when test="$datatype='date'"&gt; Date&lt;/xsl:when&gt;&lt;/xsl:choose&gt; get&lt;xsl:value-of select="$columnName" /&gt;() {&lt;br /&gt;        return &lt;xsl:call-template name="camelCaseTheColumn"&gt;&lt;xsl:with-param name="column" select="$columnName" /&gt;&lt;/xsl:call-template&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public void set&lt;xsl:value-of select="$columnName" /&gt;(&lt;xsl:choose&gt;&lt;xsl:when test="$datatype='integer'"&gt;Long &lt;/xsl:when&gt;&lt;xsl:when test="$datatype='varchar'"&gt;String &lt;/xsl:when&gt;&lt;xsl:when test="$datatype='date'"&gt;Date &lt;/xsl:when&gt;&lt;/xsl:choose&gt; &lt;xsl:call-template name="camelCaseTheColumn"&gt;&lt;xsl:with-param name="column" select="$columnName" /&gt;&lt;/xsl:call-template&gt;) {&lt;br /&gt;        this.&lt;xsl:call-template name="camelCaseTheColumn"&gt;&lt;xsl:with-param name="column" select="$columnName" /&gt;&lt;/xsl:call-template&gt; = &lt;xsl:call-template name="camelCaseTheColumn"&gt;&lt;xsl:with-param name="column" select="$columnName" /&gt;&lt;/xsl:call-template&gt;;&lt;br /&gt;    }&lt;br /&gt;		&lt;/xsl:for-each&gt;&lt;br /&gt;		&lt;br /&gt;	&lt;br /&gt;}&lt;br /&gt;		&lt;br /&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;		&lt;/xsl:for-each&gt;&lt;br /&gt;&lt;/xsl:template&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;xsl:template name="getListOfAttributes"&gt;&lt;br /&gt;        &lt;xsl:for-each select="/schema/table"&gt;&lt;br /&gt;            &lt;xsl:for-each select="columns/column"&gt;&lt;br /&gt;            &lt;xsl:variable name="columnName" select="@name" /&gt;&lt;br /&gt; this.&lt;xsl:call-template name="camelCaseTheColumn"&gt;&lt;xsl:with-param name="column" select="$columnName" /&gt;&lt;/xsl:call-template&gt; = null;&lt;/xsl:for-each&gt;&lt;br /&gt;        &lt;/xsl:for-each&gt;&lt;br /&gt;        &lt;br /&gt;    &lt;/xsl:template&gt;&lt;br /&gt;    &lt;br /&gt;        &lt;xsl:template name="getAttributeDeclarations"&gt;&lt;br /&gt;        &lt;xsl:for-each select="/schema/table"&gt;&lt;br /&gt;            &lt;xsl:for-each select="columns/column"&gt;&lt;br /&gt;            &lt;xsl:variable name="columnName" select="@name" /&gt;&lt;br /&gt;protected String &lt;xsl:call-template name="camelCaseTheColumn"&gt;&lt;xsl:with-param name="column" select="$columnName" /&gt;&lt;/xsl:call-template&gt; = null;&lt;/xsl:for-each&gt;&lt;br /&gt;        &lt;/xsl:for-each&gt;&lt;br /&gt;        &lt;br /&gt;    &lt;/xsl:template&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;xsl:template name="getSimpleAttributeList"&gt;&lt;br /&gt;        &lt;xsl:for-each select="/schema/table"&gt;&lt;br /&gt;            &lt;xsl:for-each select="columns/column"&gt;&lt;br /&gt;            &lt;xsl:variable name="columnName" select="@name" /&gt;&lt;br /&gt;&lt;xsl:call-template name="camelCaseTheColumn"&gt;&lt;xsl:with-param name="column" select="$columnName" /&gt;&lt;/xsl:call-template&gt; = null;&lt;br /&gt;&lt;/xsl:for-each&gt;&lt;br /&gt;        &lt;/xsl:for-each&gt;&lt;br /&gt;        &lt;br /&gt;    &lt;/xsl:template&gt;&lt;br /&gt;	&lt;br /&gt;	&lt;br /&gt;	&lt;xsl:template name="outputTableAndColumns"&gt;&lt;br /&gt;		&lt;xsl:for-each select="/schema/table"&gt;&lt;br /&gt;			&lt;xsl:for-each select="columns/column"&gt;&lt;br /&gt;					 ColumnName= &lt;xsl:value-of select="@name" /&gt;&lt;br /&gt;				     CamelCasedColumn: &lt;xsl:call-template name="camelCaseTheColumn"&gt;&lt;br /&gt;				&lt;xsl:with-param name="column" select="@name" /&gt;&lt;br /&gt;			&lt;/xsl:call-template&gt;&lt;br /&gt;				&lt;/xsl:for-each&gt;&lt;br /&gt;			&lt;/xsl:for-each&gt;&lt;br /&gt;	&lt;/xsl:template&gt;&lt;br /&gt;&lt;br /&gt;    &lt;xsl:template name="camelCaseTheColumn"&gt;&lt;br /&gt;        &lt;xsl:param name="column"/&gt;&lt;br /&gt;        &lt;br /&gt;        &lt;xsl:variable name='f' select='substring($column, 1, 1)'/&gt;&lt;br /&gt;        &lt;xsl:variable name='x' select='translate($f, $ucletters, $lcletters)'/&gt;&lt;br /&gt;        &lt;xsl:variable name='s' select='substring($column, 2)'/&gt;&lt;br /&gt;        &lt;xsl:value-of select="$x"/&gt;&lt;xsl:value-of select="$s"/&gt;&lt;/xsl:template&gt;&lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Jun 2008 20:12:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5682</guid>
      <author>rtperson (Roger Turnau)</author>
    </item>
    <item>
      <title>Converting text to SVG</title>
      <link>http://snippets.dzone.com/posts/show/5388</link>
      <description>First of all the Ruby code reads the text, splits it into an array and then saves it in XML format.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;a = "Open source is a development method for software that harnesses the power of distributed peer &lt;br /&gt;review and transparency of process. The promise of open source is better quality, higher reliability, &lt;br /&gt;more flexibility, lower cost, and an end to predatory vendor lock-in.".split(' ') &lt;br /&gt;&lt;br /&gt;doc = Document.new&lt;br /&gt;doc.add_element('text')&lt;br /&gt;oline = Element.new('line')&lt;br /&gt;&lt;br /&gt;char_count = 0&lt;br /&gt;a.each do |word|&lt;br /&gt;  &lt;br /&gt;  oword = Element.new('word')&lt;br /&gt;  oword.text = word.to_s&lt;br /&gt;  oword.add_attribute('length',char_count)&lt;br /&gt;  oline &lt;&lt; oword &lt;br /&gt;  char_count += word.length&lt;br /&gt;  &lt;br /&gt;  if char_count &gt; 50&lt;br /&gt;    doc.root &lt;&lt; oline&lt;br /&gt;    oline = Element.new('line')&lt;br /&gt;    char_count = 0&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;doc.root &lt;&lt; oline&lt;br /&gt;puts char_count&lt;br /&gt;puts doc&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here's a sample of the XML created&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;text&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;Open&lt;/word&gt;&lt;word length='4'&gt;source&lt;/word&gt;&lt;word length='10'&gt;is&lt;/word&gt;&lt;br /&gt;    &lt;word length='12'&gt;a&lt;/word&gt;&lt;word length='13'&gt;development&lt;/word&gt;&lt;word length='24'&gt;method&lt;/word&gt;&lt;br /&gt;    &lt;word length='30'&gt;for&lt;/word&gt;&lt;word length='33'&gt;software&lt;/word&gt;&lt;word length='41'&gt;that&lt;/word&gt;&lt;br /&gt;    &lt;word length='45'&gt;harnesses&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;the&lt;/word&gt;&lt;word length='3'&gt;power&lt;/word&gt;&lt;br /&gt;    &lt;word length='8'&gt;of&lt;/word&gt;&lt;word length='10'&gt;distributed&lt;/word&gt;&lt;word length='21'&gt;peer&lt;/word&gt;&lt;br /&gt;    &lt;word length='25'&gt;review&lt;/word&gt;&lt;word length='31'&gt;and&lt;/word&gt;&lt;word length='34'&gt;transparency&lt;/word&gt;&lt;br /&gt;    &lt;word length='46'&gt;of&lt;/word&gt;&lt;word length='48'&gt;process.&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;The&lt;/word&gt;&lt;br /&gt;    &lt;word length='3'&gt;promise&lt;/word&gt;&lt;word length='10'&gt;of&lt;/word&gt;&lt;word length='12'&gt;open&lt;/word&gt;&lt;br /&gt;    &lt;word length='16'&gt;source&lt;/word&gt;&lt;word length='22'&gt;is&lt;/word&gt;&lt;word length='24'&gt;better&lt;/word&gt;&lt;br /&gt;    &lt;word length='30'&gt;quality,&lt;/word&gt;&lt;word length='38'&gt;higher&lt;/word&gt;&lt;word length='44'&gt;reliability,&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;more&lt;/word&gt;&lt;word length='4'&gt;flexibility,&lt;/word&gt;&lt;word length='16'&gt;lower&lt;/word&gt;&lt;br /&gt;    &lt;word length='21'&gt;cost,&lt;/word&gt;&lt;word length='26'&gt;and&lt;/word&gt;&lt;word length='29'&gt;an&lt;/word&gt;&lt;br /&gt;    &lt;word length='31'&gt;end&lt;/word&gt;&lt;word length='34'&gt;to&lt;/word&gt;&lt;word length='36'&gt;predatory&lt;/word&gt;&lt;br /&gt;    &lt;word length='45'&gt;vendor&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;lock-in.&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;&lt;/text&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The XML is then transformed to SVG using the following XSL file&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:output encoding="UTF-8"&lt;br /&gt;            method="xml"&lt;br /&gt;            indent="yes"/&gt;&lt;br /&gt;            &lt;br /&gt;  &lt;xsl:template match="text"&gt;&lt;br /&gt;    &lt;svg xmlns="http://www.w3.org/2000/svg" width="100%"&lt;br /&gt;                  xmlns:xlink="http://www.w3.org/1999/xlink" &gt;&lt;br /&gt;      &lt;g id="sketch" class="sketch"&gt;&lt;br /&gt;        &lt;xsl:apply-templates select="line"/&gt;&lt;br /&gt;      &lt;/g&gt;&lt;br /&gt;    &lt;/svg&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;xsl:template match="line"&gt;&lt;br /&gt;    &lt;xsl:variable name="xfactor"&gt;12&lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="yfactor"&gt;20&lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="pos" select="position()"&gt;&lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:apply-templates select="word"&gt;&lt;br /&gt;      &lt;xsl:with-param name="xfactor" select="$xfactor"&gt;&lt;/xsl:with-param&gt;&lt;br /&gt;      &lt;xsl:with-param name="y" select="$pos * $yfactor + 10"&gt;&lt;/xsl:with-param&gt;&lt;br /&gt;    &lt;/xsl:apply-templates&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;br /&gt;  &lt;xsl:template match="word"&gt;&lt;br /&gt;    &lt;xsl:param name="xfactor"/&gt;&lt;br /&gt;    &lt;xsl:param name="y"/&gt;&lt;br /&gt;    &lt;text xmlns="http://www.w3.org/2000/svg" font-size="12pt" x="{@length * $xfactor +10}" y="{$y}" id="t1"&gt;&lt;xsl:value-of select="."/&gt;&lt;/text&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The final &lt;a href="http://www.twitxr.com/image/31865/"&gt;SVG output&lt;/a&gt; [twitxr.com] shows 5 lines of text with each word as a separate SVG text element.</description>
      <pubDate>Fri, 18 Apr 2008 18:14:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5388</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Passing an XSL param from one template to another</title>
      <link>http://snippets.dzone.com/posts/show/5387</link>
      <description>&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;&lt;br /&gt;&lt;xsl:stylesheet version="1.0"&lt;br /&gt;xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:variable name="xx"&gt;&lt;br /&gt;  &lt;html&gt;&lt;br /&gt;  &lt;body&gt;&lt;br /&gt;  &lt;xsl:call-template name="show_title"&gt;&lt;br /&gt;    &lt;xsl:with-param name="title" /&gt;&lt;br /&gt;  &lt;/xsl:call-template&gt;&lt;br /&gt;  &lt;/body&gt;&lt;br /&gt;  &lt;/html&gt;&lt;br /&gt;&lt;/xsl:variable&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:template name="show_title" match="/"&gt;&lt;br /&gt;  &lt;xsl:param name="title" /&gt;&lt;br /&gt;  &lt;xsl:for-each select="catalog/cd"&gt;&lt;br /&gt;    &lt;p&gt;Title: &lt;xsl:value-of select="$title" /&gt;&lt;/p&gt;&lt;br /&gt;  &lt;/xsl:for-each&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;source: &lt;a href="http://www.w3schools.com/XSL/el_param.asp"&gt;XSLT &lt;xsl:param&gt; Element&lt;/a&gt; [w3schools.com]</description>
      <pubDate>Fri, 18 Apr 2008 15:00:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5387</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Using XSLT to generate SVG</title>
      <link>http://snippets.dzone.com/posts/show/5375</link>
      <description>This XSL file is intended to be used as an SVG XSL template file which displays SVG content using Gorg (XSLT back-end processor).&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:output encoding="UTF-8"&lt;br /&gt;            method="xml"&lt;br /&gt;            indent="yes"/&gt;&lt;br /&gt;            &lt;br /&gt;  &lt;xsl:template match="mainpage"&gt;&lt;br /&gt;  &lt;svg xmlns="http://www.w3.org/2000/svg" width="100%"&lt;br /&gt;                xmlns:xlink="http://www.w3.org/1999/xlink" &gt;&lt;br /&gt;&lt;br /&gt;    &lt;g&gt;&lt;br /&gt;    &lt;text font-size="12pt" x="50" y="50" id="t2" stroke="olive"&gt;&lt;xsl:value-of select="title"/&gt;&lt;/text&gt;&lt;br /&gt;    &lt;/g&gt;&lt;br /&gt;&lt;br /&gt;  &lt;/svg&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Reference: 'using XSLT to generate SVG' http://snurl.com/24pwo [carto.net] </description>
      <pubDate>Thu, 17 Apr 2008 10:45:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5375</guid>
      <author>jrobertson (James Robertson)</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>Display a filtered list using XSLT</title>
      <link>http://snippets.dzone.com/posts/show/5177</link>
      <description>Following on from the post &lt;a href="http://snippets.dzone.com/posts/show/5174"&gt;A simple XSLT example&lt;/a&gt; [dzone.com], this code lists all files which have the type 'rb' (equivalent to ls *.rb).&lt;br /&gt;&lt;br /&gt;file: dir.xsl&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;&lt;br /&gt;      &lt;br /&gt;    &lt;xsl:template match="dir"&gt;&lt;br /&gt;    &lt;div id="articles"&gt;&lt;br /&gt;      &lt;ul&gt;&lt;br /&gt;      &lt;xsl:apply-templates select="records/file[@type='rb']"/&gt;&lt;br /&gt;      &lt;/ul&gt;&lt;br /&gt;    &lt;/div&gt;&lt;br /&gt;    &lt;/xsl:template&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;xsl:template match="records/file[@type='rb']"&gt;&lt;br /&gt;      &lt;li&gt;&lt;xsl:value-of select="."/&gt;&lt;/li&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;output:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;div id='articles'&gt;&lt;br /&gt;  &lt;ul&gt;&lt;br /&gt;    &lt;li&gt;projxmlhelper.rb&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;feedpopulated.rb&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;squrl_handler.rb&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;password_handler.rb&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;category.rb&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;gwd.rb&lt;/li&gt;&lt;br /&gt;  &lt;/ul&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;*update 11:58am 26-Feb*&lt;br /&gt;Here's a filter I will be using in my projects&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;&lt;br /&gt;      &lt;br /&gt;    &lt;xsl:template match="dir"&gt;&lt;br /&gt;    &lt;div id="articles"&gt;&lt;br /&gt;      &lt;ul&gt;&lt;br /&gt;      &lt;xsl:apply-templates select="records/file"/&gt;&lt;br /&gt;      &lt;/ul&gt;&lt;br /&gt;    &lt;/div&gt;&lt;br /&gt;    &lt;/xsl:template&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;xsl:template match="records/file"&gt;&lt;br /&gt;      &lt;xsl:if test="@type=$type"&gt;&lt;br /&gt;        &lt;li&gt;&lt;xsl:value-of select="."/&gt;&lt;/li&gt;&lt;br /&gt;      &lt;/xsl:if&gt;&lt;br /&gt;    &lt;/xsl:template&gt;&lt;br /&gt;    &lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 26 Feb 2008 11:47:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5177</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>A simple XSLT example</title>
      <link>http://snippets.dzone.com/posts/show/5174</link>
      <description>Produce a list of filenames using XML and XSLT&lt;br /&gt;&lt;br /&gt;file: dir.xsl&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;&lt;br /&gt;      &lt;br /&gt;    &lt;xsl:template match="dir"&gt;&lt;br /&gt;    &lt;div id="articles"&gt;&lt;br /&gt;      &lt;ul&gt;&lt;br /&gt;      &lt;xsl:apply-templates select="records/file"/&gt;&lt;br /&gt;      &lt;/ul&gt;&lt;br /&gt;    &lt;/div&gt;&lt;br /&gt;    &lt;/xsl:template&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;xsl:template match="records/file"&gt;&lt;br /&gt;      &lt;li&gt;&lt;xsl:value-of select="."/&gt;&lt;/li&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;&lt;br /&gt;file: dir.xml&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;dir&gt;&lt;br /&gt;  &lt;summary&gt;&lt;br /&gt;    &lt;directory&gt;./&lt;/directory&gt;&lt;br /&gt;  &lt;/summary&gt;&lt;br /&gt;  &lt;records&gt;&lt;br /&gt;    &lt;file type='xml'&gt;mjournal.xml&lt;/file&gt;&lt;br /&gt;    &lt;file type='rb'&gt;projxmlhelper.rb&lt;/file&gt;&lt;br /&gt;    &lt;file type='rb'&gt;feedpopulated.rb&lt;/file&gt;&lt;br /&gt;    &lt;file type='rb'&gt;squrl_handler.rb&lt;/file&gt;&lt;br /&gt;    &lt;file type='cgi'&gt;snurl.cgi&lt;/file&gt;&lt;br /&gt;    &lt;file type='cgi'&gt;dynalert.cgi&lt;/file&gt;&lt;br /&gt;    &lt;file type='rb'&gt;password_handler.rb&lt;/file&gt;&lt;br /&gt;    &lt;file type='rb'&gt;category.rb&lt;/file&gt;&lt;br /&gt;    &lt;file type='rb'&gt;gwd.rb&lt;/file&gt;&lt;br /&gt;    &lt;file type='cgi'&gt;new-journal-entry.cgi&lt;/file&gt;&lt;br /&gt;  &lt;/records&gt;&lt;br /&gt;&lt;/dir&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;then transforming the XML with the command 'xsltproc dir.xsl dir.xml' produces the following:&lt;br /&gt;output: &lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;div id='articles'&gt;&lt;br /&gt;  &lt;ul&gt;&lt;br /&gt;    &lt;li&gt;mjournal.xml&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;projxmlhelper.rb&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;feedpopulated.rb&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;squrl_handler.rb&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;snurl.cgi&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;dynalert.cgi&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;password_handler.rb&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;category.rb&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;gwd.rb&lt;/li&gt;&lt;br /&gt;    &lt;li&gt;new-journal-entry.cgi&lt;/li&gt;&lt;br /&gt;  &lt;/ul&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 25 Feb 2008 21:44:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5174</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Save a Ruby source text file to XML.</title>
      <link>http://snippets.dzone.com/posts/show/5163</link>
      <description>This code will output a text file as an XML file which can later be transformed into an HTML file using a back-end XSLT processor called Gorg.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/ruby &lt;br /&gt;&lt;br /&gt;#file: rubytxt2xml.rb&lt;br /&gt;&lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;class RubyTxt2XML&lt;br /&gt;  &lt;br /&gt;  def rubytxt2xml(h)&lt;br /&gt;    h[:infilepath] = './' if h[:infilepath].nil?&lt;br /&gt;    h[:outfilepath] = './' if h[:outfilepath].nil?&lt;br /&gt;    h[:xmlfile] = h[:sourcefile][/^(.*)\.\w+$/,1] + '.xml' if h[:xmlfile].nil?&lt;br /&gt;    buffer = File.new(h[:infilepath] + h[:sourcefile],'r').read&lt;br /&gt;    &lt;br /&gt;    doc = Document.new&lt;br /&gt;    doc.add_element('ruby_txt')&lt;br /&gt;    body = Element.new('source')&lt;br /&gt;    body.text = CData.new(buffer)&lt;br /&gt;    doc.root.add_element(body)&lt;br /&gt;    &lt;br /&gt;    file = File.new(h[:outfilepath] + h[:xmlfile],'w')&lt;br /&gt;    file.puts doc&lt;br /&gt;    file.close&lt;br /&gt;    &lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;if __FILE__ == $0&lt;br /&gt;  rt2x = RubyTxt2XML.new&lt;br /&gt;  rt2x.rubytxt2xml(:sourcefile  =&gt; 'rubytxt2xml.rb')&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;output:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;ruby_txt&gt;&lt;br /&gt;  &lt;source&gt;&lt;br /&gt;    &lt;![CDATA[&lt;br /&gt;      #!/usr/bin/ruby &lt;br /&gt;&lt;br /&gt;      #file: rubytxt2xml.rb&lt;br /&gt;&lt;br /&gt;      require 'rexml/document'&lt;br /&gt;      include REXML&lt;br /&gt;&lt;br /&gt;      class RubyTxt2XML&lt;br /&gt;        &lt;br /&gt;        def rubytxt2xml(h)&lt;br /&gt;          h[:infilepath] = './' if h[:infilepath].nil?&lt;br /&gt;          h[:outfilepath] = './' if h[:outfilepath].nil?&lt;br /&gt;          h[:xmlfile] = h[:sourcefile][/^(.*)\.\w+$/,1] + '.xml' if h[:xmlfile].nil?&lt;br /&gt;          buffer = File.new(h[:infilepath] + h[:sourcefile],'r').read&lt;br /&gt;          &lt;br /&gt;          doc = Document.new&lt;br /&gt;          doc.add_element('ruby_txt')&lt;br /&gt;          body = Element.new('source')&lt;br /&gt;          body.text = CData.new(buffer)&lt;br /&gt;          doc.root.add_element(body)&lt;br /&gt;          &lt;br /&gt;          file = File.new(h[:outfilepath] + h[:xmlfile],'w')&lt;br /&gt;          file.puts doc&lt;br /&gt;          file.close&lt;br /&gt;          &lt;br /&gt;        end&lt;br /&gt;      end&lt;br /&gt;&lt;br /&gt;      if __FILE__ == $0&lt;br /&gt;        rt2x = RubyTxt2XML.new&lt;br /&gt;        rt2x.rubytxt2xml(:sourcefile  =&gt; 'rubytxt2xml.rb')&lt;br /&gt;      end&lt;br /&gt;    ]]&gt;&lt;br /&gt;  &lt;/source&gt;&lt;br /&gt;&lt;/ruby_txt&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 22 Feb 2008 15:18:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5163</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Using XSLT to convert a value to upper or lowercase</title>
      <link>http://snippets.dzone.com/posts/show/5160</link>
      <description>This code was copied from &lt;a href="http://www.topxml.com/xsl/articles/caseconvert/"&gt;XSLT Case Conversion Solution &lt;/a&gt; [topxml.com]&lt;br /&gt;&lt;br /&gt;Firstly lets place all the letters of the alphabet, lower case and upper case in variables.&lt;br /&gt;&lt;code&gt;&lt;xsl:variable name="lcletters"&gt;abcdefghijklmnopqrstuvwxyz&lt;/xsl:variable&gt;&lt;br /&gt;&lt;xsl:variable name="ucletters"&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;/xsl:variable&gt;&lt;/code&gt;&lt;br /&gt;To then convert our data to upper case we use the translate method, which replaces all the lower case characters with upper case.&lt;br /&gt;&lt;code&gt;&lt;xsl:value-of select="translate($toconvert,$lcletters,$ucletters)"/&gt;&lt;/code&gt;&lt;br /&gt;Lower Case Transformation&lt;br /&gt;&lt;br /&gt;The lower case transformation is basically the same:&lt;br /&gt;&lt;code&gt;&lt;xsl:value-of select="translate($toconvert,$ucletters,$lcletters)"/&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Thu, 21 Feb 2008 20:20:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5160</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
  </channel>
</rss>
