attachment_descs.xsl
author ali@yendor.vm.bytemark.co.uk
Thu Nov 16 08:30:26 2006 +0000 (2006-11-16)
changeset 0 ae7b3fa753dc
permissions -rw-r--r--
First cut. Distintly raw around the edges:
* Assumes it will be running in /home/ali/wk/slashem/web.scripts
* Assumes cache directory will be in topdir
* No build system (simple compiling and linking against libxml2)
* No configure system (eg., tagsoup)
* Output XML untested
* Doesn't set bugzilla maintainer or exporter
* Handling of artifact priorities and resolution is suspect
     1 <?xml version="1.0"?>
     2 
     3 <!-- This style sheet takes a sourceforge artifact in html and outputs
     4      the attachment descriptions that it finds. The output is as follows:
     5      <attachments>
     6        <attachment>
     7          <attachid>###</attachid>
     8 	 <desc>...</desc>
     9        </attachment>
    10        ...
    11      </attachments>
    12 -->
    13 
    14 <xsl:stylesheet version="1.0"
    15 		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    16 		xmlns:xhtml="http://www.w3.org/1999/xhtml"
    17 		exclude-result-prefixes="xhtml">
    18 
    19 <xsl:template match="xhtml:tr" mode="download">
    20   <attachment>
    21     <attachid>
    22       <xsl:value-of select="substring-before(substring-after(xhtml:td[4]/descendant::xhtml:a/@href,'file_id='),'&amp;')"/>
    23     </attachid>
    24     <desc>
    25       <xsl:value-of select="normalize-space(xhtml:td[3])"/>
    26     </desc>
    27   </attachment>
    28 </xsl:template>
    29 
    30 <xsl:template match="xhtml:table[preceding-sibling::xhtml:h4='Attached Files:' and xhtml:tr/xhtml:td='Download']">
    31     <xsl:for-each select="xhtml:tr[descendant::xhtml:a='Download']">
    32       <xsl:apply-templates select="." mode="download"/>
    33     </xsl:for-each>
    34 </xsl:template>
    35 
    36 <xsl:template match="/">
    37   <attachments>
    38     <xsl:apply-templates/>
    39     <!-- A null description used as a fallback for when there is no
    40          description listed for an attachment. -->
    41     <desc xml:id="null"/>
    42   </attachments>
    43 </xsl:template>
    44 
    45 <xsl:template match="node()" priority="-1">
    46   <xsl:apply-templates/>
    47 </xsl:template>
    48 
    49 <xsl:template match="text()" priority="-1"></xsl:template>
    50 
    51 </xsl:stylesheet>