Warning: file_put_contents() [function.file-put-contents]: Only 0 of 196 bytes written, possibly out of free disk space in /disk2/home/symphonyweb/public_html/extensions/xmlfield/fields/field.xml.php on line 63
“Head JS” – XSLT Utilities – Download – Symphony.
Author:
rainerborene
Version:
0.2
Release Date:
1 Feb 2011
Category:
Output

Description

You don’t have to write JS in a ugly way when you have the power of XSLT functions in your hands. This is a cool utility that provides some useful functions related to jQuery and headjs.

XSLT

View Raw
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:exsl="http://exslt.org/common"
	xmlns:func="http://exslt.org/functions"
	xmlns:head="http://headjs.com"
	extension-element-prefixes="exsl func head">

<!--
	Define a variable in your master or somewhere else.
	
	<xsl:variable name="javascripts">
		<js>http://booya.symphonian.com/js/app.js</js>
		<js>....</js>
	</xsl:variable>
	
	<xsl:copy-of select="head:js($javascripts)"/>
	
	It loads the local jQuery if you're in the development
	environment, otherwise grabs jQuery library from Google.

	<xsl:copy-of select="head:jquery()"/>
-->

<func:function name="head:js">
	<xsl:param name="files"/>

	<func:result>
		<xsl:if test="exsl:node-set($files)/*">
			<xsl:element name="script">
				<xsl:attribute name="type">text/javascript</xsl:attribute>
				<xsl:text>head.js(</xsl:text>
				<xsl:for-each select="exsl:node-set($files)/*">
					<xsl:text>"</xsl:text>
					<xsl:value-of select="text()"/>
					<xsl:text>"</xsl:text>
					<xsl:if test="following-sibling::node()">
						<xsl:text>, </xsl:text>
					</xsl:if>
				</xsl:for-each>
				<xsl:text>);</xsl:text>
			</xsl:element>
		</xsl:if>
	</func:result>
</func:function>

<func:function name="head:jquery">
	<xsl:param name="src" select="concat($root, '/symphony/assets/jquery.js')"/>
	<xsl:param name="secure" select="contains($root, 'https://')"/>
	<xsl:param name="drop-type" select="false()"/>
	
	<func:result>
		<xsl:element name="script">
			<xsl:if test="$drop-type = true()">
				<xsl:attribute name="type">text/javascript</xsl:attribute>
			</xsl:if>
			<xsl:attribute name="src">
				<xsl:choose>
					<xsl:when test="contains($root, 'http://localhost')">
						<xsl:value-of select="$src"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:choose>
							<xsl:when test="$secure"><xsl:text>https://</xsl:text></xsl:when>
							<xsl:otherwise><xsl:text>http://</xsl:text></xsl:otherwise>
						</xsl:choose>

						<xsl:text>ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
		</xsl:element>
	</func:result>
</func:function>
	
</xsl:stylesheet>

Discuss this XSLT Utility

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