Symphony – XSLT Utilities http://symphony-cms.com Symphony XSLT Utilities en Symphony CMS XML to JSON http://symphony-cms.com/download/xslt-utilities/view/64195/ Mon, 30 Apr 2012 08:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/64195/ <h4><em>Complete XML to JSON converter.</em></h4><p><strong>By vladG</strong></p><p>A complete XML to JSON converter.</p> <p>Taken from <a href="http://code.google.com/p/xml2json-xslt/">Doeke Zanstra's xml2json utility</a>, it's packed and ready to use.</p> <p>See the <a href="http://code.google.com/p/xml2json-xslt/wiki/TransformingRules">docs</a> for more info.</p> Get the next day of a date http://symphony-cms.com/download/xslt-utilities/view/86027/ Wed, 28 Mar 2012 09:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/86027/ <h4><em>Returns the next date from a given date</em></h4><p><strong>By dbraband</strong></p><p>This snippet returns the next day.</p> <p>Leap year (29.04.2012) calculation is not implemented.</p> Convert XML-nodesets to string http://symphony-cms.com/download/xslt-utilities/view/79266/ Wed, 29 Feb 2012 08:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/79266/ <h4><em>XML, string, nodeset</em></h4><p><strong>By iwyg</strong></p><h3>Converts a nodeset to string, especially useful for json conversions.</h3> <p>===================================================================================</p> <p>Copyright 2011, Thomas Appel, http://thomas-appel.com, mail(at)thomas-appel.com dual licensed under MIT and GPL license http://dev.thomas-appel.com/licenses/mit.txt http://dev.thomas-appel.com/licenses/gpl.txt</p> <p>Github repository: <a href="https://github.com/iwyg/xml-nodeset-to-string">https://github.com/iwyg/xml-nodeset-to-string</a></p> <p>===================================================================================</p> <h3>Example usage:</h3> <p>(convert a exsl nodeset to string: )</p> <hr /><pre><code>&lt;xsl:variable name="somelink"&gt; &lt;a href="{url}" class="some-class"&gt;&lt;xsl:value-of select="name"/&gt;&lt;/a&gt; &lt;/xsl:variable&gt; &lt;xsl:apply-templates select="exsl:node-set($somelink)/* | exsl:node-set($some-link)/text()" mode="nodetostring"/&gt; </code></pre> <hr /><p>(convert xml noset to string: )</p> <hr /><pre><code>&lt;xsl:apply-templates select="node | node[text()" mode="nodetostring"/&gt; </code></pre> Czech pluralizer http://symphony-cms.com/download/xslt-utilities/view/83467/ Sun, 22 Jan 2012 09:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/83467/ <h4><em></em></h4><p><strong>By janiczek</strong></p><p>Czech pluralizer - based on <a href="http://symphony-cms.com/download/xslt-utilities/view/31778/">phoque's pluralizer</a>, but adjusted for Czech language - supports different words for 0, 1, 2-4 and 5+ things.</p> Members Forms http://symphony-cms.com/download/xslt-utilities/view/68948/ Sun, 11 Dec 2011 09:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/68948/ <h4><em>Get Members up and running</em></h4><p><strong>By michael-e</strong></p><p>This collection of XSLT utilities will help you integrate the Members extension into your Symphony website. It can save many hours (probably days) of work.</p> <p>Members Forms can be downloaded from Github: <a href="http://github.com/michael-e/members-forms">http://github.com/michael-e/members-forms</a></p> URL http://symphony-cms.com/download/xslt-utilities/view/81479/ Mon, 05 Dec 2011 23:27:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/81479/ <h4><em>Get URL according to the pages' ID</em></h4><p><strong>By kanduvisla</strong></p><p>Get the URL of a page, according to a given ID.</p> <p>Example usage:</p> <pre><code>&lt;xsl:call-template name="url"&gt; &lt;xsl:with-param name="id" select="35" /&gt; &lt;/xsl:call-template&gt; </code></pre> String utility functions http://symphony-cms.com/download/xslt-utilities/view/54569/ Thu, 01 Dec 2011 09:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/54569/ <h4><em>Lowercase, Uppercase, Replace, Split, Count substrings ...</em></h4><p><strong>By Zimmen</strong></p><h1>String utility functions (yes, functions)</h1> <pre><code>version: 1.03 author: Simon de Turck email: simon@zimmen.com </code></pre> <p>Maintained on <a href="https://gist.github.com/1415416">gist</a></p> <p>To use these functions add the string namespace to your master (or wherever you feel it suits best) stylesheet and import this utility. Add the namespace <code>xmlns:string="http://symphony-cms.com/functions"</code> to all stylesheets where you want to use these functions.</p> <p><em>This utility uses some <strong>EXSLT</strong> that is supported in libxslt 1.0.19 and later</em></p> <p>Usage:</p> <h4>Convert string to lowercase:</h4> <pre><code>&lt;xsl:value-of select="string:lower-case([selector])" /&gt; </code></pre> <h6>example:</h6> <pre><code>&lt;xsl:value-of select="string:lower-case('ABC')" /&gt; abc </code></pre> <h4>Convert string to uppercase:</h4> <pre><code>&lt;xsl:value-of select="string:upper-case([selector])" /&gt; </code></pre> <h6>example:</h6> <pre><code>&lt;xsl:value-of select="string:upper-case('abc')" /&gt; ABC </code></pre> <h4>Capitalize string (by vladG?):</h4> <pre><code>&lt;xsl:value-of select="capitalize([selector])" /&gt; &lt;xsl:value-of select="ucfirst([selector])" /&gt; (alias) </code></pre> <h6>example:</h6> <pre><code>&lt;xsl:value-of select="capitalize('the t in this sentence is capitalized!')" /&gt; The t in this sentence is capitalized! </code></pre> <h4>Capitalize each word in a string:</h4> <pre><code>&lt;xsl:value-of select="capitalize-words([selector])" /&gt; &lt;xsl:value-of select="ucall([selector])" /&gt; (alias) </code></pre> <h6>example:</h6> <pre><code>&lt;xsl:value-of select="capitalize-words('all words in this sentence are capitalized!')" /&gt; All Words In This Sentence Are Capitalized ! </code></pre> <h4>Replace in string:</h4> <pre><code>&lt;xsl:value-of select="string:replace([selector],[needle],[replace])" /&gt; </code></pre> <h6>example:</h6> <pre><code>&lt;xsl:value-of select="string:replace('a b c',' ',' to the ')" /&gt; a to the b to the c </code></pre> <h4>Split a string (returns a nodeset):</h4> <pre><code>&lt;xsl:copy-of select="string:split([selector][,[delimiter],[rootnodename],[nodename]])" /&gt; </code></pre> <ul><li>Default delimiter: ','</li> <li>Default rootnodename: 'nodeset'</li> <li>Default nodename: 'node'</li> </ul><h6>example 1:</h6> <pre><code>&lt;xsl:copy-of select="string:split('a,b,c')" /&gt; &lt;nodeset&gt; &lt;node&gt;a&lt;/node&gt; &lt;node&gt;b&lt;/node&gt; &lt;node&gt;c&lt;/node&gt; &lt;/nodeset&gt; </code></pre> <h6>example 2:</h6> <pre><code>&lt;xsl:copy-of select="string:split('book1#book2#book3','#','bookstore','book')" /&gt; &lt;bookstore&gt; &lt;book&gt;book1&lt;/book&gt; &lt;book&gt;book2&lt;/book&gt; &lt;book&gt;book3&lt;/book&gt; &lt;/bookstore&gt; </code></pre> <h6>example 3:</h6> <pre><code>&lt;xsl:copy-of select="string:split('item1#item2#item3','#','ul','li')" /&gt; &lt;ul&gt; &lt;li&gt;book1&lt;/li&gt; &lt;li&gt;book2&lt;/li&gt; &lt;li&gt;book3&lt;/li&gt; &lt;/ul&gt; </code></pre> <h4>Count occurrences of a string in a string (by phoque):</h4> <p><strong>To count elements (lets say <code>&lt;a href&gt;</code>'s in your text fields) you should use <code>count(text/*/a)</code> instead.</strong></p> <pre><code>&lt;xsl:value-of select="string:substring-count([needle],[haystack])" /&gt; </code></pre> <h6>example</h6> <pre><code>&lt;xsl:value-of select="string:substring-count('the quick brown fox jumps over the lazy dog','the')" /&gt; 2 </code></pre> group by position http://symphony-cms.com/download/xslt-utilities/view/80505/ Mon, 14 Nov 2011 09:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/80505/ <h4><em></em></h4><p><strong>By Cremol</strong></p><p>This utility applies a template loop for multiple items instead of just one item<br /><a href="http://symphony-cms.com/discuss/thread/80344/">View example</a> </p> Alphabet http://symphony-cms.com/download/xslt-utilities/view/80198/ Wed, 09 Nov 2011 04:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/80198/ <h4><em>Display the alphabet</em></h4><p><strong>By tarakanoff</strong></p><p>This template is designed to display the alphabet in the form of links (or whatever you like, decide for yourself). By default, it displays the English alphabet.</p> <p>The original algorithm is taken from the article "<a href="http://erum.ru/article/23">XSLT-examples. Vol.3 Index funds XSLT</a>" (Russian).</p> Facebook Comments http://symphony-cms.com/download/xslt-utilities/view/79066/ Mon, 17 Oct 2011 10:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/79066/ <h4><em>Implement with HTML5 or XFBML</em></h4><p><strong>By jstar</strong></p><p>A simple utility for Facebook Comments.</p> <p>See more information:</p> <p><a href="http://developers.facebook.com/docs/reference/plugins/comments/">http://developers.facebook.com/docs/reference/plugins/comments/</a></p> Converting decimal to hexadecimal http://symphony-cms.com/download/xslt-utilities/view/78502/ Thu, 06 Oct 2011 04:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/78502/ <h4><em></em></h4><p><strong>By tarakanoff</strong></p><p>Converting decimal to hexadecimal. An example of a template:</p> <pre><code>&lt;xsl:call-template name="ConvertDecToHex"&gt; &lt;xsl:with-param name="index"&gt;15&lt;/xsl:with-param&gt; &lt;/xsl:call-template&gt; </code></pre> Get File Extension http://symphony-cms.com/download/xslt-utilities/view/77812/ Fri, 23 Sep 2011 09:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/77812/ <h4><em>Get the extension of a filename</em></h4><p><strong>By kanduvisla</strong></p><p>Get the extension of a filename.</p> <p>Usage example:</p> <pre><code>&lt;xsl:call-template name="get-file-extension"&gt; &lt;xsl:with-param name="path" select="my-upload/filename" /&gt; &lt;/xsl:call-template&gt; </code></pre> Suffix http://symphony-cms.com/download/xslt-utilities/view/77434/ Thu, 15 Sep 2011 09:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/77434/ <h4><em>Put a suffix after a number</em></h4><p><strong>By kanduvisla</strong></p><p>Puts a suffix after a number:<br /> 1 becomes 1st<br /> 5 becomes 5th<br /> 302 becomes 302nd </p> <p>Usage:</p> <pre><code>&lt;xsl:call-template name="suffix"&gt; &lt;xsl:with-param name="number" select="xpath/to/my/number" /&gt; &lt;xsl:with-param name="sup" select="true()" /&gt; &lt;/xsl:call-template&gt; </code></pre> <p>The parameter <code>sup</code> determines if the suffix should be shown in a <sup>-element</sup></p> HTML5 Master Stylesheet (XHTML syntax with indenting) http://symphony-cms.com/download/xslt-utilities/view/70969/ Wed, 14 Sep 2011 09:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/70969/ <h4><em>Easily publish HTML5</em></h4><p><strong>By DavidOliver</strong></p><p>A master stylesheet starting point based on the discussion in <a href="http://symphony-cms.com/discuss/thread/43003/">XSLT and HTML5</a> and what might be thought of as current best practices for handling non-JavaScript browsers and Internet Explorer CSS rendering bugs.</p> <p>It is intended for use in conjunction with the <em>html5_doctype</em> Symphony extension and the <em>Modernizr</em> JavaScript library.</p> <p>A comprehensive range of Internet Explorer version-specific classes is available on the html tag for CSS styling without loading of separate CSS files.</p> <h2>Necessary steps</h2> <h3>html5_doctype Symphony extension</h3> <p>Install and enable the <a href="https://github.com/domain7/html5_doctype">html5_doctype Symphony extension</a>, which replaces the XHTML output in the first few lines of your document with HTML5 equivalents.</p> <h3>Modernizr</h3> <p>Download your <a href="http://www.modernizr.com/">modernizr.js</a> file and place it into workspace/scripts</p> <p>Modernizr changes the "no-js" class of the html tag to "js" if the visiting browser is using JavaScript, allowing you to write CSS specific to visitors with and without JavaScript.</p> <p>It also makes Internet Explorer render and style the new HTML5 elements (assuming JavaScript is enabled in the visitor's browser).</p> <p>GitHub repository: <a href="https://github.com/DavidOliver/html5masterxslt">https://github.com/DavidOliver/html5masterxslt</a></p> Decimal to Fraction http://symphony-cms.com/download/xslt-utilities/view/76976/ Tue, 06 Sep 2011 03:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/76976/ <h4><em>Fast Decimal to Fraction.</em></h4><p><strong>By qnn</strong></p><p>This utility takes in a decimal number and converts it to fraction string (0.5 -&gt; 1/2).</p> <p>I have been sitting on it for a while and I do not really remember if there were any bugs left. In general, it seems to be working just fine, but it has not been tested in production environment and on large datasets. </p> Twitter Button Utility http://symphony-cms.com/download/xslt-utilities/view/76582/ Wed, 31 Aug 2011 15:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/76582/ <h4><em>Easily add a Twitter button to your site</em></h4><p><strong>By bzerangue</strong></p><p>Easily add a Twitter button to your website. </p> <p>To do so...</p> <pre><code>&lt;xsl:call-template name="twitter-button"&gt; &lt;xsl:with-param name="data-url" select="'put-url-that-you-want-to-tweet-about-here'"/&gt; &lt;xsl:with-param name="data-count" select="'horizontal'"/&gt; &lt;/xsl:call-template&gt; </code></pre> Google +1 Utility http://symphony-cms.com/download/xslt-utilities/view/75540/ Sun, 14 Aug 2011 16:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/75540/ <h4><em>Easily add a Google +1 Button</em></h4><p><strong>By bzerangue</strong></p><p><strong>Description</strong></p> <p>Have you wanted to added a Google +1 Button to your site? Here’s a basic utility allowing you to do that easily.</p> <p><strong>Basic usage:</strong></p> <p>Import this utility to your existing xslt template and then call the template name="google-plus-one" like so...</p> <p><em>(Required Parameter is url, all the other parameters are optional)</em></p> <p><strong>EXAMPLE ONE (this will default to standard size)</strong></p> <pre><code>&lt;xsl:call-template name="google-plus-one"&gt; &lt;xsl:with-param name="url" select="'http://site.com'" /&gt; &lt;/xsl:call-template&gt; </code></pre> <p><strong>EXAMPLE TWO (defining size, will use select another size other than standard)</strong></p> <pre><code>&lt;xsl:call-template name="google-plus-one"&gt; &lt;xsl:with-param name="url" select="'http://site.com'" /&gt; &lt;xsl:with-param name="size" select="'small'" /&gt; &lt;/xsl:call-template&gt; </code></pre> Plaintext Paragraphs http://symphony-cms.com/download/xslt-utilities/view/75484/ Sun, 14 Aug 2011 09:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/75484/ <h4><em>Wraps plaintext paragraphs with HTML paragraph elements</em></h4><p><strong>By jensscherbl</strong></p><p>Pimped the <a href="http://symphony-cms.com/download/xslt-utilities/view/26522/">nl2br</a> utility to wrap plaintext paragraphs with HTML paragraph elements before inserting HTML line breaks in a string.</p> <p>Credits to <a href="http://symphony-cms.com/download/xslt-utilities/view/26522/">nl2br</a>, only changed and added a few lines.</p> Video JS http://symphony-cms.com/download/xslt-utilities/view/72167/ Mon, 11 Jul 2011 08:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/72167/ <h4><em>A draft embedding html5 video using videojs</em></h4><p><strong>By iwyg</strong></p><p>This is a rough example on how I implemented html5 video. Adapt this utility to your needs, In this specific case I am using the <a href="http://videojs.com/">videojs player</a> Script. </p> <p>changelog:</p> <ul><li>2011.07.11: Fixed a typo that prevented Flash fallback from loading the video file</li> </ul><p>Example Setup:</p> <ul><li>create a video section</li> <li>create uploadfields for video files (mp4, webm, ogg, flv)</li> <li>create an uploadfield named 'poster</li> <li>create a selectbox for choosing the video player's skin. Name it 'skin' and set values to 'default, tube, vim, hu'</li> <li>if you don't provide a specific flv file, flash player will try to play the given mp4 file</li> </ul><p>in our xsl do something like:</p> <pre><code> &lt;xsl:call-template name="videojs"&gt; &lt;xsl:with-param name="videoWidth" select="'778'" /&gt; &lt;xsl:with-param name="videoHeight" select="'438'" /&gt; &lt;xsl:with-param name="source" select="." /&gt; &lt;xsl:with-param name="showDownloadLink" select="true()" /&gt; &lt;/xsl:call-template&gt; </code></pre> <p>where param source ('.') should point to your 'video/entry' xpath</p> <p>(example for backend view, using Nick Dunns HTML panel field extension)</p> <p><img src="https://github.com/iwyg/videojs-utility/raw/master/doc/videojs_be.png" alt="" /></p> E-mail link http://symphony-cms.com/download/xslt-utilities/view/72705/ Tue, 28 Jun 2011 09:00:00 +1000 http://symphony-cms.com/download/xslt-utilities/view/72705/ <h4><em>for clickable, scrambled e-mail links</em></h4><p><strong>By kanduvisla</strong></p><p>Generates human-unreadable e-mail addresses in your source-code, while using JavaScript to convert these to clickable e-mail addresses on the go!</p> <h2>Usage:</h2> <p>On pages where you want to use this template, you first need to include a small javascript-function called 'strtr'. You can do this with the following XSLT:</p> <pre><code>&lt;xsl:call-template name="strtr-function" /&gt; </code></pre> <p>Secondly, to create an e-mail link use:</p> <pre><code>&lt;xsl:call-template name="e-mail-link"&gt; &lt;xsl:with-param name="e-mail" select="e-mail-address (for example)" /&gt; &lt;xsl:with-param name="value" select="'Send a mail'" /&gt; &lt;/xsl:call-template&gt; </code></pre> <p>Optional parameters are attributes to add to the anchor-tag:</p> <ul><li>class</li> <li>id</li> <li>title</li> <li>rel</li> </ul>