Search

just wondering, when do you guys think the xslt utilities page will be functional for us to start posting snippets in there?

edit. while awaiting the release of s2 rc1 and more overture functionality, here is a temporary page for anyone willing to put their hard worked xslt templates to the masses

Not sure, but we're definitely going to finish S2 first before working on Overture. You could start a thread for interesting utilities or utility requests in the meantime if you like.

figured as much...i'll change this thread to a temporary xslt utilities page then.

Serial Lists, example 1 (courtesy of Allen Chang)

This example, and the following, are utilities that will parse tag lists, multiple selects, etc., and correctly format as serial lists. So if there are two items, it will render "item1 and item2", for three or more, "item1, item2, and item3" and so on.

 <xsl:template match="section/item">
    <xsl:choose>
        <xsl:when test="position() = last() and position() &gt; 1"><xsl:text> and </xsl:text>  
        </xsl:when>
        <xsl:when test="position() &gt; 1"><xsl:text>, </xsl:text></xsl:when>
    </xsl:choose>
    <a href=""><xsl:value-of select="."/></a>
 </xsl:template>

Serial Lists, example 2 (courtesy of Allen Chang)

 <xsl:template match="section/item">
     <xsl:text>, </xsl:text>
     <a href=""><xsl:value-of select="."/></a>
 </xsl:template>

 <xsl:template match="section/item[1]" priority="1">
     <a href=""><xsl:value-of select="."/></a>
 </xsl:template>

 <xsl:template match="section/item[position() = last()]">
     <xsl:text> and </xsl:text>
     <a href=""><xsl:value-of select="."/></a>
 </xsl:template>

List Creation The purpose of this template is to create a series of lists (&lt;li&gt;), breaking at nth item.

I commented some of the template to try and make it easier to follow. if you're still having a hard time with it, feel free to post back in here or email me. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

&lt;xsl:template name="list-wrap" mode="list"&gt;
  &lt;div id="list_wrap"&gt;
    &lt;xsl:call-template name="start-list" mode="list" /&gt;
&lt;!-- 
  start out the template. you can add the following params into the `call-template` and 
overwrite the default settings: 
* $item - to start from 
* $bot-range -  this is used when you loop back into the template to tell which node position() 
you want to start the new list from, 
* $top-range - how many you want to have in your list. defaults to 10 per.
* $inc - number of items you want in a list
--&gt;
  &lt;/div&gt;
&lt;/xsl:template&gt;

&lt;xsl:template name="start-list" mode="list"&gt;
&lt;!-- corresponds to the position of each category, starting from 1 --&gt;
  &lt;xsl:param name="item" select="1"/&gt;
  &lt;xsl:param name="bot-range" select="1" /&gt;
  &lt;xsl:param name="top-range" select="10" /&gt;
  &lt;xsl:param name="inc" select="10" /&gt;
    &lt;!-- although $top-range and $inc equal each other, you still need both.
    $top-range gets overwritten later on in the template so you need some
    constant for $inc --&gt;
&lt;!-- counts how many categories there are --&gt;
  &lt;xsl:variable name="count-items" select="count(page/entry)" /&gt;
  &lt;xsl:if test="$item &lt;= $count-items"&gt;
      &lt;!-- create list - this can also be changed to suit your needs --&gt;
  &lt;ul class="items_list"&gt;
      &lt;!-- begin the call to create the &lt;li&gt;s --&gt;
    &lt;xsl:call-template name="make-list" mode="list"&gt;
      &lt;xsl:with-param name="bot-range" select="$bot-range" /&gt;
      &lt;xsl:with-param name="top-range" select="$top-range" /&gt;
      &lt;xsl:with-param name="item" select="$item" /&gt;
      &lt;xsl:with-param name="count-items" select="$count-items" /&gt;
    &lt;/xsl:call-template&gt;
  &lt;/ul&gt;
  &lt;/xsl:if&gt;
  &lt;!-- If there are still more category items to go through, run this template again --&gt;
  &lt;xsl:if test="$item &lt; $count-items"&gt;
    &lt;xsl:call-template name="start-list" mode="list"&gt;
      &lt;xsl:with-param name="item" select="$item + $inc" /&gt;
      &lt;xsl:with-param name="bot-range" select="$bot-range + $inc" /&gt;
      &lt;xsl:with-param name="top-range" select="$top-range + $inc" /&gt;
    &lt;/xsl:call-template&gt;
  &lt;/xsl:if&gt;
&lt;/xsl:template&gt;

    &lt;!-- increment your ranges with each successive pass --&gt;
&lt;xsl:template name="make-list" mode="list"&gt;
  &lt;xsl:param name="bot-range" /&gt;
  &lt;xsl:param name="top-range" /&gt;
  &lt;xsl:param name="item" /&gt;
  &lt;xsl:param name="count-items" /&gt;
  &lt;xsl:apply-templates select="page_one" mode="list"&gt;
    &lt;xsl:with-param name="bot-range" select="$bot-range" /&gt;
    &lt;xsl:with-param name="top-range" select="$top-range" /&gt;
    &lt;xsl:with-param name="pos" select="$item" /&gt;
  &lt;/xsl:apply-templates&gt;
      &lt;!-- recall this template if your $item position() is still less than your $top-range number --&gt;
  &lt;xsl:if test="$item &lt; $top-range"&gt;
    &lt;xsl:call-template name="make-list" mode="list"&gt;
      &lt;xsl:with-param name="bot-range" select="$bot-range" /&gt;
      &lt;xsl:with-param name="top-range" select="$top-range" /&gt;
      &lt;xsl:with-param name="item" select="$item + 1" /&gt;
    &lt;/xsl:call-template&gt; 
  &lt;/xsl:if&gt;
&lt;/xsl:template&gt;

    &lt;!-- builds out the actual &lt;li&gt; --&gt;
&lt;xsl:template match="page_one" mode="list"&gt;
  &lt;xsl:param name="bot-range" /&gt;
  &lt;xsl:param name="top-range" /&gt;
  &lt;xsl:param name="pos" /&gt;
  &lt;li&gt;
    &lt;xsl:apply-templates select="entry[$pos]" mode="list" /&gt;
  &lt;/li&gt;
&lt;/xsl:template&gt;

    &lt;!--  grab the content for your list  --&gt;
&lt;xsl:template match="entry" mode="list"&gt;
  &lt;xsl:param name="pos" /&gt;
      &lt;!-- this can be omitted, but it was used to make the href url point to single entries --&gt;
  &lt;xsl:variable name="sub-page" select="'page'" /&gt;
  &lt;a href="{$root}/{$current-page}/{$sub-page}/{title/@handle}/" title="{title}"&gt;&lt;xsl:value-of select="title" /&gt;&lt;/a&gt;
  &lt;xsl:if test="/data/events/login-info/@logged-in = 'true'"&gt;
    &lt;a href="{$root}/symphony/publish/{$current-page}/edit/{@id}/" title="Edit {title}" target="_blank"&gt;
      &lt;img class="edit" src="{$workspace}/images/edit.gif" /&gt;
    &lt;/a&gt;
  &lt;/xsl:if&gt;
&lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details