XSLT fun

Fun

1. For Christmas
2. It seems you want to launch an obfuscated XSLT contest... ;-)
3. More fun
4. The game of life
5. Game of Life-2, in XSLT
6. Happy Birthday XSLT.

1.

For Christmas

Mike Kay


A Christmas cracker


If anyone is not yet convinced that we have a rather
remarkable language on our hands, try applying this
stylesheet

<a xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0">
<xsl:value-of select="*******************"/>
</a>

to this document

<q>2</q>

Have fun!

            

2.

It seems you want to launch an obfuscated XSLT contest... ;-)

Marty McKeever


> I can't remember where i found this one, but it's kinda fun:
 

 <xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output indent="yes"/>
 <xsl:variable  name="abc"
>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</xsl:variable>
 <xsl:variable
name="rot13">NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm
  </xsl:variable>  
 <xsl:template match="*">
    <xsl:element name="{translate(name(),$abc,$rot13)}">
       <xsl:for-each select="@*">
          <xsl:attribute name="{translate(name(),$abc,$rot13)}">
 		<xsl:value-of select="translate(.,$abc,$rot13)"/>
 	  </xsl:attribute>
       </xsl:for-each>
 	<xsl:for-each select="text()">
 	<xsl:value-of select="translate(.,$abc,$rot13)"/>
 	</xsl:for-each>
 	<xsl:apply-templates select="*"/>
   </xsl:element>
 </xsl:template>
 </xsl:stylesheet>

3.

More fun

David Carlisle and Mike Ball

Try this, run it through any xslt engine, with itself as the input file.

From: David Carlisle - today's stylesheet?

<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform"
version="1.0"><output method="text"/><variable name="x"
select="'td&#xA;p HiaBr'"/><template match="*"><value-of
select="translate('xra  yw23k6hFGyw6ow','6Fx wr3G2k',$x)"/>
<choose><when test="position()=3"><value-of select=
"namespace-uri(.)"/></when><otherwise>&#121;o&#x75;</otherwise>
</choose></template><template match="/*"><apply-templates
select="*"/></template></stylesheet>

Mike Ball quickly replied

<?xml version='1.0'?><stylesheet
xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"><output
method="text"/><variable name="x" select="')elco:rsgv-&#xA; '"/><template
match="*"><value-of select="translate('x!.zfza !.b39 p71','1z.!bpa93f7x
',$x)"/></template><template match="/*"><apply-templates
select="*"/></template></stylesheet>

Ed: This is, I believe how the guru's write their stylesheets:-)

4.

The game of life

Roger Costello

I have implemented the Game of Life www.math.com using XSLT.

It's kinda neat! It nicely demonstrates some aspects of complex systems such as evolution, attractors and feedback.

For example, here is a simple starting configuration (a filled-in square means it's a live cell, an empty square means it's a dead cell): orig.html

After applying the rules of Life once, the configuration evolves to this: out1.html Then, after applying the rules of Life to that output (i.e., feedback), the configuration evolves to this: out2.html Below I chronicle the configuration's evolution. It settles into a repeating pattern when it gets to the sixth iteration (the pattern alternates between configuration 5 and 6 indefinitely). These two states represents an "attractor". out3.html, out4.html, out5.html out6.html Each configuration is represented as an XML document. Here is the initial configuration: orig-Input.xml

Here is the stylesheet which applies the Life rules, and produces the next configuration: GameOfLife.xsl Here is a stylesheet which creates a graphical image of a configuration: GameOfLifeViewer.xsl Many thanks to Tom Passin, Len Bullard, Didier Martin and Bob Foster for their excellent suggestions and insight!

5.

Game of Life-2, in XSLT

Roger Costello

I have modified the Game of Life stylesheet so that now it adapts based upon interaction with a "Population Control" stylesheet. The Population Control monitors the population (number of live cells) that the Game of Life is producing.

input.xml -> PopulationControl.xsl -> new-input.xml -> GameOfLife.xsl

-> input2.xml -> PopulationControl.xsl -> new-input2.xml

-> GameOfLife.xsl -> input3.xml -> PopulationControl.xsl -> ...

If the population is too low then the Population Control instructs the Game of Life to increase its population. The Game of Life accomplishes this by dynamically modifying its built-in rules such that the modified rules increase the likelihood of growth.

If the population is too high then the Population Control instructs the Game of Life to decrease its population. Again, the Game of Life accomplishes this by dynamically modifying its built-in rules to discourage growth.

Thus, there is a dynamic interaction between the Game of Life and Population Control. The Game of Life continually alters (adapts) itself based upon input from Population Control.

Here is a simple animation of the Game of Life as it interacts with Population Control (thanks to Bob DuCharme for showing me how to create this HTML animation): xfront.com

Here is the new version of the Game of Life stylesheet: xfront.com Here is the Population Control stylesheet: http://www.xfront.com/adaptive-life/PopulationControl.xslxfront.com Many thanks to Didier and Len for their help and suggestions.

6.

Happy Birthday XSLT.

Dimitre and Jorris.

Sent to the list on 10 Febrary 2005

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform"> <output method="xml"/><template match="/"><for-each select="document('')/*"><element name="{translate(*[1]/@*,'*xaybzcl','*iaybzcg')}" namespace=""> <attribute name="{translate(*[1]/@*,'*xaymzcl','*sayrzcc')}"> <value-of select="concat(concat(substring-before(namespace::*,'1'), '2003/02/'),(document(concat(substring-before(namespace::*,'1'), '2003/02/',*[1]/@*,translate(local-name(*[2]/@*), 'mch','--'),count(//*)-2,'.html'))//*[contains(text(),'!')][1]/following::*/@src)[1])"/> </attribute></element></for-each></template></stylesheet>

and from Joris

 <stylesheet version="1.0" 
 xmlns="http://www.w3.org/1999/XSL/Transform">
 <output method="xml"/><template match="/"><for-each 
 select="document('')/*"> <copy-of 
 select="document(concat(substring-before(namespace::*,'1'),
 '2003/02/',*[1]/@*,translate(local-name(*[2]/@*),
 'mch','--'),count(//*),'.html'))//*[contains(text(),'!')][1]"/>
 </for-each></template></stylesheet>