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
ali@0
     1
<?xml version="1.0"?>
ali@0
     2
ali@0
     3
<!-- This style sheet takes a sourceforge artifact in html and outputs
ali@0
     4
     the attachment descriptions that it finds. The output is as follows:
ali@0
     5
     <attachments>
ali@0
     6
       <attachment>
ali@0
     7
         <attachid>###</attachid>
ali@0
     8
	 <desc>...</desc>
ali@0
     9
       </attachment>
ali@0
    10
       ...
ali@0
    11
     </attachments>
ali@0
    12
-->
ali@0
    13
ali@0
    14
<xsl:stylesheet version="1.0"
ali@0
    15
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
ali@0
    16
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
ali@0
    17
		exclude-result-prefixes="xhtml">
ali@0
    18
ali@0
    19
<xsl:template match="xhtml:tr" mode="download">
ali@0
    20
  <attachment>
ali@0
    21
    <attachid>
ali@0
    22
      <xsl:value-of select="substring-before(substring-after(xhtml:td[4]/descendant::xhtml:a/@href,'file_id='),'&amp;')"/>
ali@0
    23
    </attachid>
ali@0
    24
    <desc>
ali@0
    25
      <xsl:value-of select="normalize-space(xhtml:td[3])"/>
ali@0
    26
    </desc>
ali@0
    27
  </attachment>
ali@0
    28
</xsl:template>
ali@0
    29
ali@0
    30
<xsl:template match="xhtml:table[preceding-sibling::xhtml:h4='Attached Files:' and xhtml:tr/xhtml:td='Download']">
ali@0
    31
    <xsl:for-each select="xhtml:tr[descendant::xhtml:a='Download']">
ali@0
    32
      <xsl:apply-templates select="." mode="download"/>
ali@0
    33
    </xsl:for-each>
ali@0
    34
</xsl:template>
ali@0
    35
ali@0
    36
<xsl:template match="/">
ali@0
    37
  <attachments>
ali@0
    38
    <xsl:apply-templates/>
ali@0
    39
    <!-- A null description used as a fallback for when there is no
ali@0
    40
         description listed for an attachment. -->
ali@0
    41
    <desc xml:id="null"/>
ali@0
    42
  </attachments>
ali@0
    43
</xsl:template>
ali@0
    44
ali@0
    45
<xsl:template match="node()" priority="-1">
ali@0
    46
  <xsl:apply-templates/>
ali@0
    47
</xsl:template>
ali@0
    48
ali@0
    49
<xsl:template match="text()" priority="-1"></xsl:template>
ali@0
    50
ali@0
    51
</xsl:stylesheet>