XSLT question - how to hide some items?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

XSLT question - how to hide some items?

Christian Boltz-5
Hello,

sorry for abusing this list for XSLT questions, but well, some people
here (hello Thomas!) are too good in this area ;-)

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", the second one is composed
from two <message type="info">...</message> lines.

The current XSLT file is attached - you can feed it with
    zypper --xmlout -t patch | xsltproc patch2mail.xsl -
if 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.)


Regards,

Christian Boltz
--
Werbung lügt, Corporate Design sagt die Wahrheit. Naja,
alle _guten_ Komponenten der Wahrheit. :-)      [Ratti]

patch2mail.xsl (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: XSLT question - how to hide some items?

Thomas Schraitle-2
Hi,

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.


> the second one is
> composed from two <message type="info">...</message> lines.
>
> 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>
   <message type="error">Unknown command &apos;patch&apos;</message>
   <message type="info">Type &apos;zypper help&apos; to get a list of
    global options and commands.</message>
  </stream>

# zypper --version
zypper 0.11.10


> 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. If you really need this functionality, use
the document element from the EXSLT initiative, see [1].

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


Bye,
Tom

------
[1] http://www.exslt.org/exsl/elements/document/index.html


--
Thomas Schraitle

----------------------------------------------------------------------
SUSE LINUX GmbH      >o)   Documentation Specialist
Maxfeldstrasse 5     /\\  
90409 Nuernberg     _\_v   http://en.opensuse.org/Documentation_Team
http://developer.novell.com/wiki/index.php/Lessons_for_Lizards
http://lizards.opensuse.org/author/thomas-schraitle/
---------------------------------------------------------------------
--
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: XSLT question - how to hide some items?

Christian Boltz-5
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!

zypper-xmlout-lu-t-patch-11.1 (3K) Download Attachment
patch2mail.xsl (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: XSLT question - how to hide some items?

Thomas Schraitle-2
Hi,

On Monday 08 December 2008, Christian Boltz wrote:
> [...]
>
> > # zypper --version
> > zypper 0.11.10
>
> That's an outdated zypper version ;-) - openSUSE 11.1 has zypper
> 1.0.2.

I thought so. :)


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

Looks good. No complains so far. ;-)


> [...]
> > 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 ;-)

Well, you need it when you want to have more than one output files.


> [...]
> 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>

You can omit the xsl:if clause with a predicate in "match" to make it
a bit more compact:

 <xsl:template match="message[@type='info']">
   <xsl:text>&#10;ERROR: </xsl:text>
   <xsl:apply-templates />
   <xsl:text>&#10;</xsl:text>
 </xsl:template>

Maybe you need a another template to deal with general message
elements or with other message elements that contains other values in
your @type attributes. I haven't tested it. With your given XML file
both templates work.

Well, it's a matter of style not of functionality. :)


Tom

--
Thomas Schraitle

----------------------------------------------------------------------
SUSE LINUX GmbH      >o)   Documentation Specialist
Maxfeldstrasse 5     /\\  
90409 Nuernberg     _\_v   http://en.opensuse.org/Documentation_Team
http://developer.novell.com/wiki/index.php/Lessons_for_Lizards
http://lizards.opensuse.org/author/thomas-schraitle/
---------------------------------------------------------------------
--
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: XSLT question - how to hide some items?

Karl Eichwalder
In reply to this post by Christian Boltz-5
Christian Boltz <[hidden email]> writes:

> 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).

But why?  The sooner you switch, the better.  These days, using a
non-UTF-8 encoding just hurts.

--
Karl Eichwalder
R&D / Documentation

SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg)
--
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: XSLT question - how to hide some items?

Christian Boltz-5
Hello,

on Dienstag, 9. Dezember 2008, Karl Eichwalder wrote:
> Christian Boltz <[hidden email]> writes:
> > 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).
>
> But why?  The sooner you switch, the better.

Well, there are different reasons. For example, I have several
webservers running with ISO-8859-15. Uploading HTML documents with
UTF-8 encoding causes some interesting charset problems. And I'm not
planning to switch these servers to UTF-8 because this would mean to
change lots of (often customer's) files...

> These days, using a non-UTF-8 encoding just hurts.

Well, it depends (see above) and I don't really need klingon characters
for my daily work.

Oh, and using ISO-8859-15 is quite useful while betatesting - I found
several charset problems this way which would have been unnoticed
otherwise ;-)


Regards,

Christian Boltz
--
> [wikibot] jfyi: we have an internal ruby script that works with
> iChain. we used it for the SDB migration (did you really expect
> we uploaded 2000pages manually?;)
Considering you have nothing else to do, yes. ;-)
[Marcus Rueckert and houghi in opensuse-wiki]
--
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: XSLT question - how to hide some items?

Christian Boltz-5
In reply to this post by Thomas Schraitle-2
Hello,

on Dienstag, 9. Dezember 2008, Thomas Schraitle wrote:
> On Monday 08 December 2008, Christian Boltz wrote:
...
> > I'll attach zypper output from 11.1 (and the updated XSLT file) in
> > case you want to test it.
>
> Looks good. No complains so far. ;-)

Thanks for checking it!

> > [...]
> >
> > > 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 ;-)
>
> Well, you need it when you want to have more than one output files.

Then I really don't need it. There's only one /dev/stdout ;-)

> > [...]
> > I found a working solution:
> >
> > <!-- messages, unless type="info" -->
> > <xsl:template match="message">
> >   <xsl:if test="@type != 'info'">

> You can omit the xsl:if clause with a predicate in "match" to make it
> a bit more compact:
>
>  <xsl:template match="message[@type='info']">
                                     ^
Shouldn't it be "!=" instead of "="?

> Maybe you need a another template to deal with general message
> elements or with other message elements that contains other values in
> your @type attributes. I haven't tested it. With your given XML file
> both templates work.
>
> Well, it's a matter of style not of functionality. :)

Then I'll keep the xsl:if ;-) and commit an updated patch2mail to the
buildservice later.


Regards,

Christian Boltz
--
> rpmdb: PANIC: fatal region error detected; run recovery
Du wohnst nicht zufällig in Bielefeld?
[> Cornelia Böttge und Michael Raab in opensuse-de]
--
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: XSLT question - how to hide some items?

Karl Eichwalder
In reply to this post by Christian Boltz-5
Christian Boltz <[hidden email]> writes:

> Oh, and using ISO-8859-15 is quite useful while betatesting - I found
> several charset problems this way which would have been unnoticed
> otherwise ;-)

I'd rather say this encoding is the problem ;)

--
Karl Eichwalder
R&D / Documentation

SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg)
--
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: XSLT question - how to hide some items?

Thomas Schraitle-2
In reply to this post by Christian Boltz-5
Hi,

On Tuesday 09 December 2008, Christian Boltz wrote:

> [...]
> > > [...]
> > > I found a working solution:
> > >
> > > <!-- messages, unless type="info" -->
> > > <xsl:template match="message">
> > >   <xsl:if test="@type != 'info'">
> >
> > You can omit the xsl:if clause with a predicate in "match" to
> > make it a bit more compact:
> >
> >  <xsl:template match="message[@type='info']">
>
>                                      ^
> Shouldn't it be "!=" instead of "="?

Ahh, you're right.


> > Maybe you need a another template to deal with general message
> > elements or with other message elements that contains other
> > values in your @type attributes. I haven't tested it. With your
> > given XML file both templates work.
> >
> > Well, it's a matter of style not of functionality. :)
>
> Then I'll keep the xsl:if ;-) and commit an updated patch2mail to
> the buildservice later.

Whatever you like. Just to show you another possibilitiy. :)


Tom

--
Thomas Schraitle

----------------------------------------------------------------------
SUSE LINUX GmbH      >o)   Documentation Specialist
Maxfeldstrasse 5     /\\  
90409 Nuernberg     _\_v   http://en.opensuse.org/Documentation_Team
http://developer.novell.com/wiki/index.php/Lessons_for_Lizards
http://lizards.opensuse.org/author/thomas-schraitle/
---------------------------------------------------------------------
--
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]