Skip to content

Instantly share code, notes, and snippets.

Created September 6, 2013 16:07
Show Gist options
  • Save anonymous/6466013 to your computer and use it in GitHub Desktop.
Save anonymous/6466013 to your computer and use it in GitHub Desktop.
<data>
<entry>
<caption mode="formatted">
<p>A fairly long looking <a href="http://www.stackoverflow.com">caption with a link</a> that goes to an external site.</p>
</caption>
</entry>
<entry>
<caption mode="unformatted">
<![CDATA[A fairly long looking <a href="http://www.stackoverflow.com">caption with a link</a> that goes to an external site.]]>
</caption>
</entry>
</data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
<xsl:include href="https://gist.github.com/andrewminton/6465924/raw/72d6f6833a282da5ef0d2a8aa22087f71150a59e/nodetostring" />
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:apply-templates select="data/entry"/>
</xsl:template>
<xsl:template match="data/entry">
<xsl:variable name="html-ready">
<xsl:apply-templates select="caption/*"/>
</xsl:variable>
<!-- process contents of caption node-->
<!-- stringify it -->
<li>
<xsl:copy-of select="$cap"/> //outside of attribute it works
<img>
<xsl:attribute name="src">/image/2/150/112/5<xsl:value-of select="@path"/>/<xsl:value-of select="filename"/></xsl:attribute>
<xsl:attribute name="data-caption">
<xsl:call-template name="nodetostring">
<xsl:with-param name="node" select="$html-ready"/>
<xsl:with-param name="esc-dblq" select="true()"/>
</xsl:call-template>
</xsl:attribute>
</img>
</li>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment