Search

 <xsl:if>

Could the above be typed as:

<if>

Hi. Is possible to drop the xsl: in XSL tags?

Curious to know. I can think of some advantages and some disadvantages. For example a disadvantage would conflicting namespaces/tags. If you have an opinion on this - the good, bad, ugly of such a technique, I like to know your thoughts good or bad too?

My thoughts:

XSL is a beautiful creature. I am not trying to make it appear like a language it is not (much of the logic seems to also draw parallels to the mind set needed for evented programming which will be evermore relevant soon). However it is often appears verbose on the eye, if not very verbose; hiding a beautiful logic lying within an XSL stylesheet. When using a haml or jade template preprocessor I am often wondering: could be such a thing for XSL? In Symphony we use Markdown. Are we using Markdown for people who cant use, or will deviate from, basic HTML, or because it is easier to write and read than HTML.

I would love to hear anyone opinions, thoughts or even spraffings similar to my own here.

Cheers, Ross

The xsl: prefix is used as you mentioned to disambiguate between what is an XSLT instruction versus elements you want in your output result.

You are however free to change the xsl: namespace to whatever you want:

xmlns:x="http://www.w3.org/1999/XSL/Transform"

The above will allow you to write, <x:value-of select="node"/>

Disambiguation (in another words, namespacing) is necessary as element name conflicts would be an ongoing issue. Even if we somehow created a pre-processor to figure out what are XSLT instructions v.s. HTML/XML for output, both the syntax for XSLT and HTML can grow and change as newer versions are introduced. For example, in XSLT, we have <xsl:element>. The node name <element> is common in the XML space. It could also be introduced in later version of HTML.

If you really wanted to, I think you could also add the xsl namespace as the default:

xmlns="http://www.w3.org/1999/XSL/Transform"

But this would require also namespacing anything being output from the transform (usually html). The html you output is usually in the 'null' namespace, because the xslt doc isn't given a default namespace, and your output html isn't usually given a prefix. Your xslt would end up having something like:

xmlns:w='http://www.w3.org/1999/xhtml'

as a ns declaration, and a template such as:

<template match="/">
<w:div>Here is some content</w:div>
</template>

As you can see, you'd probably end up adding more prefix characters to the code than you'd remove. I think there are probably other smaller issues to it as well.

While there is no actual standard for it, switching up the prefixes can make your templates less portable, since you can't cut and paste in and out of the XSLT doc without checking to be sure the namespaces are in order.

Thanks for these answers & explanations.

I'm keen to try this out on a next project. Even if just during development phases, for myself. Currently I tend to use very little output code within my stylesheets spare the odd <ul> or <li> here and there. I presume it would be possible to make a small utility/snippet to switch the namespaces in an editor.

Doing a find and replace (xsl: > ) in my editor is bliss.

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