Recently I've been playing with jquery and python. Panos and I have created Boombox, a site providing Greek music and in general music that's popular in Greece. Check it out!




XSLT sometimes can be a pain in the bum, for sure it's not one of my favorite languages. :)
So today, I was trying to fix the following problem:
XML snippet looked like this:
<tag1>
text 1
<tag11>
<tag12>text 2</tag12>
</tag11>
text 3
<tag21>
text 4
<tag22>text 5</tag22>
</tag21>
text 6
</tag1>
I wanted my output to look like this:
text 1 text 2 text 3 text 4 <a href="blah">text 5</a> text 6.
So pretty much what I needed to do was to get the text value of each node except from tag22 node, in which case I wanted to apply a template and output it as an anchor tag.
Here is the XSLT snippet which produces the desired result:
<xsl:apply-templates select="tag1" mode="foo"/> <xsl:template match="text()" mode="foo"> <xsl:value-of select"."/> </xsl:template> <xsl:template match="*" mode="foo"> <xsl:apply-templates mode="foo"/> </xsl:template> <xsl:template match="tag22" mode="foo"> <a href="blah"><xsl:value-of select="."/></a> </xsl:template>
Let me try to explain whats going on here.