Skip to content

Instantly share code, notes, and snippets.

@LeifW
Created March 31, 2010 06:27
Show Gist options
  • Save LeifW/350008 to your computer and use it in GitHub Desktop.
Save LeifW/350008 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom">
<xsl:template match="atom:entry">
<xsl:for-each select="atom:link[@rel='enclosure']">
<xsl:apply-templates select=".." mode="copy">
<xsl:with-param name="enclosure" select="position()"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
<xsl:template match="atom:entry" mode="copy">
<xsl:param name="enclosure"/>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:copy-of select="atom:link[@rel='enclosure'][$enclosure]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="atom:link[@rel='enclosure']"/>
<!-- Identity template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<<<?xml version="1.0" encoding="UTF-8"?>>>
xsl:stylesheet -version=1.0 -xmlns:xsl=http://www.w3.org/1999/XSL/Transform -xmlns:atom=http://www.w3.org/2005/Atom
template atom:entry
for-each atom:link[@rel='enclosure']
apply-templates .. copy
with-param enclosure position()
template atom:entry -mode=copy
param enclosure
copy
apply-templates @*|node()
copy-of atom:link[@rel='enclosure'][$enclosure]
template atom:link[@rel='enclosure']
-- Identity template
template @*|node()
copy
apply-templates @*|node()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment