Hello, I want to mail some documentation about available updates to root ;-) and hope that this makes this mail less off-topic here *g* - I need a bit help from XML/XSLT experts which I expect to be in the doc team ;-)
In short: I have written a xsl file that filters the output of
zypp-checkpatches-wrapper to send an update notification mail to root.
It basically works, however I have some problems with the whitespace.
Current output:
---------------------------------------------------------------------
# xsltproc patch2mail.xsl zypp.xml
*** ERROR ***
Some error during calculation happened
*** ERROR ***
Another error
Update sources:
ftp.gwdg.de (http://ftp.gwdg.de/pub/suse/update/10.1)
irgendwo (http://ftp.irgendwo.de)
=== java-1_5_0-sun - Patch 1438-0 (security) ===
SUN Java packages prior 1.5.0 update 7 allow DOS.
Sun Java Runtime Environment (JRE) 1.5.0_6 and earlier, JDK
1.5.0_6 and earlier, and SDK 1.5.0_6 and earlier allows
remote attackers to cause a denial of service (disk
consumption) by using the Font.createFont function to
create temporary files of arbitrary size in the %temp%
directory (CVE-2006-2426).
=== java-1_5_0-sun - Patch 1438-0 (security) ===
SUN Java packages prior 1.5.0 update 7 allow DOS.
Sun Java Runtime Environment (JRE) 1.5.0_6 and earlier, JDK
1.5.0_6 and earlier, and SDK 1.5.0_6 and earlier allows
remote attackers to cause a denial of service (disk
consumption) by using the Font.createFont function to
create temporary files of arbitrary size in the %temp%
directory (CVE-2006-2426).
Total updates: 2 (2 security)
__TOTAL__22__
---------------------------------------------------------------------
The fact that the same patch is listed twice is caused by my test file
(zypp.xml, attached) - don't worry about this ;-)
Also don't worry about the __TOTAL__ line - this is easier to parse by
my script.
I'd like to have
- no empty at the very beginning
- "*** ERROR ***", "Update sources" and "=== ... ===" without leading
whitespace
- an empty line after the patch summary
- less empty lines before "Total updates"
Can someone help me with these issues?
The xslt and the script calling it are attached to this mail, also the
test data (zypp.xml) I used.
Regards,
Christian Boltz, searching for a good sig ;-)
--
xslt, was? Wir kombinieren das Paradigma von awk mit der
sprachlichen Eleganz von Cobol und den programmiertechnischen
Verrenkungen von funktionalen Sprachen unter sorgfältiger
Umgehung aller möglichen Vorteile. [Kristian Köhntopp]
patch2mail
Description: application/shellscript
<?xml version="1.0" encoding="ISO-8859-15"?>
<!--
Copyright (c)2007 Christian Boltz - www.cboltz.de
License: GPL v2 or any later version
-->
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- <xsl:output method="text" encoding="ISO-8859-15" media-type="text/plain" /> -->
<xsl:template match="/"><xsl:apply-templates /></xsl:template>
<xsl:template match="update-status">
<xsl:document href="-" method="text" ><xsl:apply-templates />
</xsl:document></xsl:template>
<!-- errors -->
<xsl:template match="errors"><xsl:apply-templates /></xsl:template>
<xsl:template match="errors/error">*** ERROR ***
<xsl:apply-templates />
</xsl:template>
<!-- update sources -->
<xsl:template match="update-sources">Update sources:<xsl:apply-templates /></xsl:template>
<xsl:template match="update-sources/source"><xsl:value-of select="@alias" /> (<xsl:value-of select="@url" />)</xsl:template>
<!-- updates -->
<xsl:template match="update-list"><xsl:apply-templates /></xsl:template>
<xsl:template match="update-list/update">=== <xsl:value-of select="@name" /> - Patch <xsl:value-of select="@edition" /> (<xsl:value-of select="@category" />) ===<xsl:apply-templates /></xsl:template>
<xsl:template match="update-list/update/summary">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="update-list/update/description"><xsl:apply-templates /></xsl:template>
<!--
<xsl:template match="update-list/update/source">Update source: <xsl:value-of select="@alias" /> (<xsl:value-of select="@url" />)</xsl:template>
-->
<!-- summary -->
<xsl:template match="update-summary">
Total updates: <xsl:value-of select="@total" /> (<xsl:value-of select="@security" /> security)
__TOTAL__<xsl:value-of select="@total" /><xsl:value-of select="@security" />__
</xsl:template>
<!-- end -->
</xsl:stylesheet>
<?xml version='1.0'?> <update-status version="0.4"> <errors> <error>Some error during calculation happened</error> <error>Another error</error> </errors> <update-sources> <source url="http://ftp.gwdg.de/pub/suse/update/10.1" alias="ftp.gwdg.de"/> <source url="http://ftp.irgendwo.de" alias="irgendwo"/> </update-sources> <update-list> <update category="security" name="java-1_5_0-sun" edition="1438-0"> <summary>SUN Java packages prior 1.5.0 update 7 allow DOS.</summary> <description>Sun Java Runtime Environment (JRE) 1.5.0_6 and earlier, JDK 1.5.0_6 and earlier, and SDK 1.5.0_6 and earlier allows remote attackers to cause a denial of service (disk consumption) by using the Font.createFont function to create temporary files of arbitrary size in the %temp% directory (CVE-2006-2426). </description> <source url="http://ftp.gwdg.de/pub/suse/update/10.1" alias="http://ftp.gwdg.de/pub/suse/update/10.1"/> </update> <update category="security" name="java-1_5_0-sun" edition="1438-0"> <summary>SUN Java packages prior 1.5.0 update 7 allow DOS.</summary> <description>Sun Java Runtime Environment (JRE) 1.5.0_6 and earlier, JDK 1.5.0_6 and earlier, and SDK 1.5.0_6 and earlier allows remote attackers to cause a denial of service (disk consumption) by using the Font.createFont function to create temporary files of arbitrary size in the %temp% directory (CVE-2006-2426). </description> <source url="http://ftp.gwdg.de/pub/suse/update/10.1" alias="http://ftp.gwdg.de/pub/suse/update/10.1"/> </update> </update-list> <update-summary total="2" security="2"/> </update-status>
