XML/XSLT and Extensibility

Continuing my thread of CMS investigations – I am currently searching for a CMS that will do what I want to do. Part of the problem is that I have worked with far too many CMS products which are great for client sites, but not so much for my itty-bitty site. Yes, the argument could be made that instead of upgrading to a bigger (and by definition better) CMS in the future as the site grows, why not just install the behemoth at the moment and be done with it.

Here is a list of some of the CMS’s that I have worked with and why I am probably not going to choose them for my site…

  1. Vignette – too big and too expensive, even for the so-called Vignette Certified Practitioners, it can take 5 days to install!1
  2. OpenCMS – free, which is good, requires a JVM which I don’t have access to yet…2. It does have a ‘static export’ function which is what I want…
  3. Drupal – Theme based which is not as easy to skin if you are looking for a different layout than their header/footer, right/left/body type layout. Plenty of plugins to do what I may eventually, possibly need in the future.
  4. Alfresco – Very powerful, very complex system – more for a multi- person/site/language. Overkill for what I need
  5. Magnolia – It has been a while since I tried this one out – time to download and install…
  6. Jahia – Surprisingly, this would be my number one choice, I know how it works, how to easily set up page templates and I could have a site up and running within 2 weeks. Still, probably a little bit of overkill, although there is a ‘personal’ license, I really only need it for exporting to static HTML.

I have also evaluated the following throughout my career:

  1. Expression Engine
  2. FatWire
  3. IBM WebContent Manager
  4. Plone
  5. Joomla
  6. Typo3
  7. InterWoven

There are many other – too many to mention in fact, it seems everybody has a CMS these days.

Requirements

  • Supported on the Mac – So in any of these languages: Java, PHP, Perl, Python, Cocoa
  • Easy to template – I only need probably 3 template types, so nothing too complex for me.
  • Minimal default workflow, this is just for me I don’t need a complex system,, just write – and approve
  • No support for multi user/language/site – one site, one language, one user
  • Exportable to static HTML – until my new hosting kicks in, I won’t be using this live.

Show Stoppers

Which is where I finally get to the topic of the title.

NO XML TEMPLATES THANK YOU

I am looking at you FatWire, and to a lesser extent OpenCMS (nicer interface.

Why No XML?

Firstly, to really know ‘xslt’ you would be able to answer yes to the following:

  • How would you group XML node items? – Hint: If you are not immediately thinking of Muenchian you are probably doing it wrong
  • Recursion, and by recursion I mean:
    • Can you code an xsl template that counts from 1 to ‘n’ – in both directions – where ‘n’ is a parameter not a hard-coded value?
    • Can you code an xsl template to generate the Fibonnaci sequence for the first ‘n’ digits?
  • Have you worked with large datasets? (i.e. MegaBytes and over – what problems to you have when they reach the next order of magnitude?)
  • Do you have a function library wich you use for most of your projects?

I am not talking about XSLT when you are going through a simple example, you need to have experience with generating a lot of content – preferably HTML (or XHTML as it would be). Then you have really learned how to use XSL.

There are many strengths with XSL, and there are two major problems as I see it:

Problem One: So Inexplicably Verbose to do the Most Simple of Tasks

If I am asked to do the following:

Translate an underscore delimited string into a camelCased string.

Simple, Easy…

In Java Land (pseudo-code ahead)

public String convertToCamelCase(String underScoreDelimitedString) {
	// don't return the tokens please
	StringTokenizer stringTokenizer = new StringTokenizer(underScoreDelimitedString, "_", false);
	
	StringBuffer stringBuffer = new StringBuffer();
	while(stringTokenizer.hasMoreTokens()) {
		String token = stringTokenizer.nextToken();
		stringBuffer.append(token.charAt(0).toUpperCase());
		stringBuffer.append(token.substring(1).toLowerCase());
	}

	return(stringBuffer.toString());
}

In XSLT land – including commends, the same function takes 76 lines (with comments – 56 without).

Here it is3:

<!--
   The following template(s) converts an underscore delimited name into a nice
   java camel case name.  Note that this comes in two different flavours
   a) converting the first character to Upper Case, and
   b) converting the first character to Lower Case.
 
   Both of these will then call the recursive template named convertNameRest
   In both, the initial characters are converted (up to 
   the first '_' character) and the second template converts the rest 
   of the string.  Note that convertUpperName is just a call on function
   that immediately calls converNameRest.
 
   for example: 
   under convertLowerName 
     ID_USER converts to idUser
   under convertUpperName
     ID_USER converts to IdUser
 -->
 
 <xsl:template name="convertUpperName">
   <!-- 
     upper case the first part of the name 
     -->
   <xsl:param name="name"/>
   <xsl:call-template name="convertNameRest">
     <xsl:with-param name="nameRest"><xsl:value-of select="$name"/></xsl:with-param>
   </xsl:call-template>
 </xsl:template>
 
 <xsl:template name="convertLowerName">
   <!-- 
     lower case the first part of the name - unless of course there are 
     no '_' characters in the field name, then just do the first letter
     -->
   <xsl:param name="name"/>
   <xsl:choose>
     <xsl:when test="string-length(substring-before($name, '_')) = 0">
       <xsl:value-of select="translate(substring($name, 1), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
     </xsl:when>
     <xsl:otherwise>
       <xsl:value-of select="translate(substring-before($name,'_'), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
       <xsl:call-template name="convertNameRest">
         <xsl:with-param name="nameRest"><xsl:value-of select="substring-after($name,'_')"/></xsl:with-param>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>

 <xsl:template name="convertNameRest">
   <!--
   The first character goes to uppercase, and the rest goes to lower case (up 
   to the '_') this is not as straightforward as it looks
   -->
   <xsl:param name="nameRest"/>
   <xsl:choose>
     <xsl:when test="string-length(substring-before($nameRest, '_')) = 0">
       <!--
       Means that this is the last of the conversion
       -->
       <xsl:value-of select="translate(substring($nameRest, 1,1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
       <xsl:value-of select="translate(substring($nameRest, 2), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
     </xsl:when>

   <xsl:otherwise>
       <!--
       There is still more converting to do - convert this part and
       pass the rest back to this function
       -->
       <xsl:value-of select="translate(substring($nameRest, 1,1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
       <xsl:value-of select="translate(substring-before(substring($nameRest, 2), '_'), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
       <xsl:call-template name="convertNameRest">
         <xsl:with-param name="nameRest"><xsl:value-of select="substring-after($nameRest,'_')"/></xsl:with-param>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>	

Problem Two: The Code Rusts

Yes, the code rusts quicker than your bathtub at the seaside. And by code rust I mean that once you have completed to code, leave it for a while and come back to it, it just doesn’t look like it makes sense. See the above example, I wrote this a long time ago, the only way for me to get it to make sense was to put in a lot of comments, even now, should there be a subtle error in it, it would be a horror to debug.

After all – I have never tested it with the string “__________” – perhaps I should…

So no XML/XSLT Templates

I know xslt/xml like the back of my hand, I can make it sing and dance, it just gets far to complex to maintain. On my current project I have generated 5,000 lines of xsl code… I haven’t looked at it in a while and I fear that I may never be able to decipher its hidden riddles again…

The search continues…

Maybe, just perhaps, you can see where I am going with these posts….

Footnotes:

  1. yes just to install the thing nothing else
  2. I am looking at macminicolo for hosting
  3. And feel free to use this one if you want – I have written a lot of function libraries for XSLT – about 1,000 lines of code that I re-use quite constantly.

Like my footnotes?
Want to add footnotes to your blog?
They can be added easily to your WordPress installation


Leave a Reply

You must be logged in to post a comment.