Hello,

(finally found some time to work on this...)

on Montag, 24. November 2008, Thomas Schraitle wrote:
> On Friday 21 November 2008, Christian Boltz wrote:
> > [...]
> > I have two small issues with my patch2mail (update notification)
> > script: It includes two lines at the end of the output which I'd
> > like to supress:
> >
> >     <?xml version="1.0"?>
> >     Daten des Repositorys laden...Installierte Pakete lesen...
> >
> > The first one is obviously the XML "header",
>
> Yes, the header is the XML declaration. That's easy to omit it:
> Insert a <xsl:output method="text"/> right after the <xsl:stylesheet>
> element.

Indeed, that helps. There was a xsl:output tag sitting around already, 
but commented out - unfortunately I don't remember why I disabled it 
(might be because it included an encoding flag).

Nevertheless: Works _with_ the xsl:output tag :-)

I also changed my wrapper script to call zypper always with LANG=C 
because I got some warnings about non-UTF8 input (I still use 
ISO-8859-15 locale).

> > The current XSLT file is attached - you can feed it with
> >     zypper --xmlout -t patch | xsltproc patch2mail.xsl -
> > if you want to test it.
>
> That doesn't work for me. If I use only the first part, I get:
>
>  <?xml version='1.0'?>
>   <stream>
>    <message type="error">--terse is not implemented, does
>      nothing</message>
...
> # zypper --version
> zypper 0.11.10

That's an outdated zypper version ;-) - openSUSE 11.1 has zypper 1.0.2.

I'll attach zypper output from 11.1 (and the updated XSLT file) in case 
you want to test it.

> > What do I have to change to remove the above lines?
> > (Note: Only messages with type "info" should be hidden.)
>
> First, fix your stylesheet. :) It contains version="1.1". As far as I
> know, this version is not really supported by libxslt. Use
> version="1.0". Especially the xsl:document element is unknown in the
> XSLT 1.0 specification. 

I changed the version and removed the xsl:document "wrap" around the 
xsl:apply-templates for <update-status /> - still seems to work.

> If you really need this functionality, use
> the document element from the EXSLT initiative, see [1].

The only functionality I need is "parse the XML and output text/plain". 
I don't really care how or why it works as long as it works ;-)

> I guess, you need a new template with match="text()" or
> match="message/text()" somewhere, but that could be a bit too
> radical.

I found a working solution:

<!-- messages, unless type="info" -->
<xsl:template match="message">
  <xsl:if test="@type != 'info'">
    <xsl:text>&#10;ERROR: </xsl:text>
    <xsl:apply-templates />
    <xsl:text>&#10;</xsl:text>
  </xsl:if>
</xsl:template>


Thanks for your help!


Regards,

Christian Boltz
-- 
Lass Dir kein X für ein U vormachen,
sei auf der Hxt!
<?xml version='1.0'?>
<stream>
 <message type="error">Manually added ERROR message ;-)</message> 
<message type="info">Daten des Repositorys laden...</message>
<message type="info">Installierte Pakete lesen...</message>
<update-status version="0.6">
<update-list>
 <update name="update-test-optional" edition="198" category="optional" 
pkgmanager="false" restart="false" interactive="false" kind="patch">
  <summary>Release tracking dummy bug  </summary>
  <description>Test update of update-test-optional
</description>
  <license></license>
  <source url="http://download.opensuse.org/update/11.1"; alias="updates-11.1"/>
 </update>
 <update name="update-test-trival" edition="201" category="recommended" 
pkgmanager="false" restart="false" interactive="false" kind="patch">
  <summary>Release tracking dummy bug for hmuelle  </summary>
  <description>test update patch
</description>
  <license></license>
  <source url="http://download.opensuse.org/update/11.1"; alias="updates-11.1"/>
 </update>
 <update name="update-test-security" edition="200" category="security" 
pkgmanager="false" restart="false" interactive="false" kind="patch">
  <summary>Release tracking dummy bug  </summary>
  <description>Test update of update-test-security
</description>
  <license></license>
  <source url="http://download.opensuse.org/update/11.1"; alias="updates-11.1"/>
 </update>
 <update name="update-test-reboot-needed" edition="199" category="recommended" 
pkgmanager="false" restart="true" interactive="true" kind="patch">
  <summary>Release tracking dummy bug for hmuelle  </summary>
  <description>Test update of update-test-reboot-needed After the update
has been installed, you will be informed to reboot to
activate the changes. We use this &quot;reboot-needed&quot; feature
for kernel updates normally.
</description>
  <license></license>
  <source url="http://download.opensuse.org/update/11.1"; alias="updates-11.1"/>
 </update>
 <update name="update-test-interactive" edition="197" category="recommended" 
pkgmanager="false" restart="false" interactive="false" kind="patch">
  <summary>Release tracking dummy bug for hmuelle  </summary>
  <description>Test update of update-test-interactive. You need to confirm
the message to get this patch update installed.
</description>
  <license></license>
  <source url="http://download.opensuse.org/update/11.1"; alias="updates-11.1"/>
 </update>
 <update name="update-test-optional" edition="202" category="optional" 
pkgmanager="false" restart="false" interactive="false" kind="patch">
  <summary>Release tracking dummy bug for hmuelle  </summary>
  <description>This bug will be used as dummy for updates with no own bug.
</description>
  <license></license>
  <source url="http://download.opensuse.org/update/11.1"; alias="updates-11.1"/>
 </update>
 <update name="update-test-optional" edition="202" category="optional" 
pkgmanager="false" restart="false" interactive="false" kind="patch">
  <summary>Release tracking dummy bug for hmuelle  </summary>
  <description>This bug will be used as dummy for updates with no own bug.
</description>
  <license></license>
  <source url="http://download.opensuse.org/update/11.1-test/"; 
alias="updates-11.1-test"/>
 </update>
 <update name="libgcrypt" edition="302" category="recommended" 
pkgmanager="false" restart="false" interactive="false" kind="patch">
  <summary>Release tracking dummy bug for hmuelle  </summary>
  <description>This update fixes the issue of a failing selftest in
gcrypt, causing a lot of dependend issues, like
gnome-key-ring not  working properly.
</description>
  <license></license>
  <source url="http://download.opensuse.org/update/11.1-test/"; 
alias="updates-11.1-test"/>
 </update>
</update-list>
</update-status>
</stream>
<?xml version="1.0" encoding="ISO-8859-15"?>
<!--

Copyright (c) 2008 Christian Boltz - www.cboltz.de

Thanks to Thomas Schraitle for helping with some xslt details.


This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License (http://www.gnu.org/copyleft/gpl.html)
for more details.

-->

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="text"/>
<!-- <xsl:output method="text" encoding="ISO-8859-15" media-type="text/plain" /> -->

<xsl:strip-space elements="*"/>


<xsl:template match="/"><xsl:apply-templates /></xsl:template>

<xsl:template match="update-status">
<xsl:apply-templates />
<!-- <xsl:document href="-" method="text" >
</xsl:document>
-->
</xsl:template>

<!-- errors -->

<xsl:template match="errors"><xsl:apply-templates /></xsl:template>

<xsl:template match="errors/error">
  <xsl:text>*** ERROR ***&#10;</xsl:text>
    <xsl:apply-templates />
  <xsl:text>&#10;&#10;</xsl:text>
</xsl:template>


<!-- update sources -->

<xsl:template match="update-sources">
  <xsl:text>Update sources:&#10;</xsl:text>
  <xsl:apply-templates />
  <xsl:text>&#10;</xsl:text>
</xsl:template>

<xsl:template match="update-sources/source">
  <xsl:text>- </xsl:text>
  <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:if test="@kind = 'patch'">
  <xsl:text>&#10;=== </xsl:text> 
  <xsl:value-of select="@name" /> 
  <xsl:text> - Patch </xsl:text>
  <xsl:value-of select="@edition" /> 
  <xsl:text> (</xsl:text>
  <xsl:value-of select="@category" />
  <xsl:text>) ===&#10;&#10;</xsl:text>
  <xsl:apply-templates />
  <xsl:text>&#10;</xsl:text>
</xsl:if>
</xsl:template>

<xsl:template match="update-list/update/summary">
   <xsl:apply-templates />
</xsl:template>

<xsl:template match="update-list/update/description">
  <xsl:text>&#10;&#10;</xsl:text>
  <xsl:apply-templates />
</xsl:template>

<!-- update source of this specific update isn't that interesting ;-) -->
<!--
<xsl:template match="update-list/update/source">Update source: <xsl:value-of select="@alias" /> (<xsl:value-of select="@url" />)</xsl:template>
-->

<!-- messages, unless type="info" -->
<xsl:template match="message">
  <xsl:if test="@type != 'info'">
    <xsl:text>&#10;ERROR: </xsl:text>
    <xsl:apply-templates />
    <xsl:text>&#10;</xsl:text>
  </xsl:if>
</xsl:template>

<!-- summary -->

<xsl:template match="update-summary">
  <xsl:text>--------------------------------------------------------&#10;&#10;</xsl:text>
  <xsl:text>    Total: </xsl:text>
  <xsl:value-of select="@total" />
  <xsl:text> updates (</xsl:text>
  <xsl:value-of select="@security" /> 
  <xsl:text> security)&#10;__TOTAL__</xsl:text>
  <xsl:value-of select="@total" /><xsl:value-of select="@security" />
  <xsl:text>__&#10;</xsl:text>
</xsl:template>


<!-- end -->

</xsl:stylesheet>

Reply via email to