Filling in HTML attributes with XSL

January 14, 2010

Problem: I want to transform some XML that looks like

<flash href="drill-1-scientific-notation" width="550" height="400"/>

into browser-independent HTML, using XSL. The output code has to copy the XML attributes into HTML attributes. I can’t use xsl:value-of tags to do that, because I can’t put tags inside of tags.

Solution: use {@attribute} wherever the value of an attribute has to be inserted. The XSL template for my flash tag looks like

<xsl:template match="flash">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="{@width}" height="{@height}" id="{@href}" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="{@href}.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="{@href}.swf" quality="high" bgcolor="#ffffff" width="{@width}" height="{@height}" name="{@href}" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: