Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

<xsl:attribute> bygga upp href, img element osv

<img>
<xsl:attribute name="src">
<xsl:value-of select="@url"/>
</xsl:attribute>
</img>

Outputen blir

<img src="xml-urlen">


Bygga upp länk, href med url data från xmlen:

<a>
<xsl:attribute name="href">
<xsl:call-template name="HREF_BUILD"/>
</xsl:attribute>
<xsl:call-template name="Les flere nyheter"/>


Länkens namn

<img src="{$urlroot}filestore/{ATTRIBUTES/ATTRIBUTE[LABEL = 'eventImage']/VALUE/FILE/FILENAME}"/>

Outputen blir

Länkens namn



xsl:attribute

The xsl:attribute allows you to add an attribute to an element. This element is often used when you need to add a source(src) to an image. Remembering that in HTML an img tag is still an element in XML term. So when we are wanting to add any of these attributes to elements, you need to use this technique.

appendInputTypeClasses() - IE attribute selectors for form inputs

(Stolen from Jeremy Keith and Dustin Diaz: http://domscripting.com/blog/display/38).

Unobtrusive script takes a form inputs type attribute and copies it to that input's class. So, you go from...

<input type="text" />


...to...

<input type="text" class="text" />


Basically allows attribute selectors for form until IE catches up.

/*
	form.js
	AUTH: Austin Govella (austin.govella@gmail.com)
	DATE: 2006-07-01
	DESC: Includes form specific javascripts.
	NOTE: Stolen from Jeremy Keith and Dustin Diaz: http://domscripting.com/blog/display/38
	REVS:  
*/



function appendInputTypeClasses()
{	/* adds input type as the inputs class */
	if ( !document.getElementsByTagName ) return;

	var inputs = document.getElementsByTagName('input');
	var inputLen = inputs.length;
	for ( i=0; i < inputLen; i++ )
	{
		if ( inputs[i].getAttribute('type') )
		{
			inputs[i].className += ' '+inputs[i].getAttribute('type');
		}
	}
}

Test whether an SGML attribute value requires quoting

SGML attribute values don't always need to be quoted; here's a quick bit of Python which returns whether an attribute value needs to be quoted or not:

import re
if re.compile('^[a-zA-Z0-9_\-\.:]+$').search(value):
   ...does not need quoting..
else:
   ...does need quoting...