I' ve written my own XSLT and I need to process it. And get output from it.
I'm using this simple code for beginning:
===================================
# !/usr/bin/perl

# import required modules
# use XML::Parser;
# use XML::XPath;
# use XML::XPath::XMLParser;
use XML::XSLT;

# define local variables
my $xslfile = "test2.xsl";
my $xmlfile = "com.redhat.rhsa-20091463.xml";

# create an instance of XSL::XSLT processor
my $xslt = XML::XSLT->new ($xslfile, warnings => 1, debug => 1);

# transforms the XML file using the XSL style sheet
$xslt->transform ($xmlfile);

# send to output
print $xslt->toString;

# free up some memory
$xslt->dispose();
=============================================
My XSL template looks:
=============================================
<xsl:stylesheet version="1.0" xmlns:ns1="http://oval.mitre.org/XMLSchema/oval-definitions-5"; xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:xs="http://www.w3.org/2001/XMLSchema";>

<xsl:output method="html" version="1.0" omit-xml-declaration="no" indent="no"
media-type="text/html" />
<xsl:template match="/">
<xsl:apply-templates select="oval_definitions/definitions/definition/criteria"
/>
</xsl:template>

<xsl:template match="criteria">
<xsl:param name="level" select="count(./parent::criteria)" />

<!--Process the element -->
<xsl:apply-templates select="." mode="name">
<xsl:with-param name="level" select="$level" />
</xsl:apply-templates>

<!-- Take the next level to an account -->
<xsl:apply-templates select="criteria">
<xsl:with-param name="level" select="$level + 1" />
</xsl:apply-templates>
</xsl:template>

<xsl:template match="criteria" mode="name">
<xsl:param name="level" />
<xsl:value-of select="concat('level :&#160;', $level,
'&#160;&#160;&#160;','[',local-name(.),']',
generate-id(..), '&#160;&#160;&#160;&#160;&#160;&#160;', generate-id(.),
'&#160;&#160;&#160;&#160;&#160;&#160;', 'operator=&quot;', @operator,'&quot;')"
/>
</xsl:template>

</xsl:stylesheet>
=========================================================
And I process this XML:
=========================================================
<?xml version="1.0" encoding="UTF-8"?>

<oval_definitions xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5"; xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5"; xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5"; xmlns:unix-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix"; xmlns:red-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd">
 <generator>
   <oval:product_name>Red Hat Errata System</oval:product_name>
   <oval:schema_version>5.3</oval:schema_version>
   <oval:timestamp>2009-09-24T15:21:57</oval:timestamp>
 </generator>

 <definitions>
<definition id="oval:com.redhat.rhsa:def:20091463" version="302" class="patch">
     <metadata>
       <title>RHSA-2009:1463: newt security update (Moderate)
   </title>
   <affected family="unix">
           <platform>Red Hat Enterprise Linux 3</platform>
            <platform>Red Hat Enterprise Linux 4</platform>
            <platform>Red Hat Enterprise Linux 5</platform>
            </affected>
<reference source="RHSA" ref_id="RHSA-2009:1463-01" ref_url="https://rhn.redhat.com/errata/RHSA-2009-1463.html"/> <description>Newt is a programming library for color text mode, widget-based user
interfaces. Newt can be used to add stacked windows, entry widgets,
checkboxes, radio buttons, labels, plain text fields, scrollbars, and so
on, to text mode user interfaces.

A heap-based buffer overflow flaw was found in the way newt processes
content that is to be displayed in a text dialog box. A local attacker
could issue a specially-crafted text dialog box display request (direct or
via a custom application), leading to a denial of service (application
crash) or, potentially, arbitrary code execution with the privileges of the
user running the application using the newt library. (CVE-2009-2905)

Users of newt should upgrade to these updated packages, which contain a
backported patch to correct this issue. After installing the updated
packages, all applications using the newt library must be restarted for the
update to take effect.</description>

<!-- ~~~~~~~~~~~~~~~~~~~~   advisory details   ~~~~~~~~~~~~~~~~~~~ -->

<advisory from="secal...@redhat.com">

       <severity>Moderate</severity>

       <rights>Copyright 2009 Red Hat, Inc.</rights>
       <issued date="2009-09-24"/>
       <updated date="2009-09-24"/>
<cve href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-2905";>CVE-2009-2905</cve> <bugzilla href="http://bugzilla.redhat.com/523955"; id="523955">CVE-2009-2905 newt: heap-overflow in textbox when text reflowing</bugzilla>
       <affected_cpe_list>
           <cpe>cpe:/o:redhat:enterprise_linux</cpe>
       </affected_cpe_list>
</advisory>
     </metadata>
     <criteria operator="OR">

<criteria operator="AND">
<criterion test_ref="oval:com.redhat.rhsa:tst:20091463001" comment="Red Hat Enterprise Linux 5 is installed" />
<criteria operator="OR">

<criteria operator="AND">
<criterion test_ref="oval:com.redhat.rhsa:tst:20091463004" comment="newt-devel is earlier than 0:0.52.2-12.el5_4.1" /><criterion test_ref="oval:com.redhat.rhsa:tst:20091463005" comment="newt-devel is signed with Red Hat redhatrelease key" />

</criteria>
<criteria operator="AND">
<criterion test_ref="oval:com.redhat.rhsa:tst:20091463002" comment="newt is earlier than 0:0.52.2-12.el5_4.1" /><criterion test_ref="oval:com.redhat.rhsa:tst:20091463003" comment="newt is signed with Red Hat redhatrelease key" />

</criteria>

</criteria>

</criteria>
<criteria operator="AND">
<criterion test_ref="oval:com.redhat.rhsa:tst:20091463006" comment="Red Hat Enterprise Linux 3 is installed" />
<criteria operator="OR">

<criteria operator="AND">
<criterion test_ref="oval:com.redhat.rhsa:tst:20091463009" comment="newt-devel is earlier than 0:0.51.5-2.el3" /><criterion test_ref="oval:com.redhat.rhsa:tst:20091463010" comment="newt-devel is signed with Red Hat master key" />

</criteria>
<criteria operator="AND">
<criterion test_ref="oval:com.redhat.rhsa:tst:20091463007" comment="newt is earlier than 0:0.51.5-2.el3" /><criterion test_ref="oval:com.redhat.rhsa:tst:20091463008" comment="newt is signed with Red Hat master key" />

</criteria>

</criteria>

</criteria>
<criteria operator="AND">
<criterion test_ref="oval:com.redhat.rhsa:tst:20091463011" comment="Red Hat Enterprise Linux 4 is installed" />
<criteria operator="OR">

<criteria operator="AND">
<criterion test_ref="oval:com.redhat.rhsa:tst:20091463013" comment="newt-devel is earlier than 0:0.51.6-10.el4_8.1" /><criterion test_ref="oval:com.redhat.rhsa:tst:20091463010" comment="newt-devel is signed with Red Hat master key" />

</criteria>
<criteria operator="AND">
<criterion test_ref="oval:com.redhat.rhsa:tst:20091463012" comment="newt is earlier than 0:0.51.6-10.el4_8.1" /><criterion test_ref="oval:com.redhat.rhsa:tst:20091463008" comment="newt is signed with Red Hat master key" />

</criteria>

</criteria>

</criteria>

</criteria>

   </definition>
 </definitions>
 <tests>
   <!-- ~~~~~~~~~~~~~~~~~~~~~   rpminfo tests   ~~~~~~~~~~~~~~~~~~~~~ -->
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463001" version="302" comment="Red Hat Enterprise Linux 5 is installed" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463001" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463003" />
</rpminfo_test>
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463002" version="302" comment="newt is earlier than 0:0.52.2-12.el5_4.1" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463002" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463004" />
</rpminfo_test>
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463003" version="302" comment="newt is signed with Red Hat redhatrelease key" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463002" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463002" />
</rpminfo_test>
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463004" version="302" comment="newt-devel is earlier than 0:0.52.2-12.el5_4.1" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463003" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463004" />
</rpminfo_test>
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463005" version="302" comment="newt-devel is signed with Red Hat redhatrelease key" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463003" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463002" />
</rpminfo_test>
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463006" version="302" comment="Red Hat Enterprise Linux 3 is installed" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463001" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463005" />
</rpminfo_test>
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463007" version="302" comment="newt is earlier than 0:0.51.5-2.el3" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463002" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463006" />
</rpminfo_test>
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463008" version="302" comment="newt is signed with Red Hat master key" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463002" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463001" />
</rpminfo_test>
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463009" version="302" comment="newt-devel is earlier than 0:0.51.5-2.el3" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463003" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463006" />
</rpminfo_test>
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463010" version="302" comment="newt-devel is signed with Red Hat master key" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463003" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463001" />
</rpminfo_test>
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463011" version="302" comment="Red Hat Enterprise Linux 4 is installed" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463001" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463007" />
</rpminfo_test>
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463012" version="302" comment="newt is earlier than 0:0.51.6-10.el4_8.1" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463002" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463008" />
</rpminfo_test>
<rpminfo_test id="oval:com.redhat.rhsa:tst:20091463013" version="302" comment="newt-devel is earlier than 0:0.51.6-10.el4_8.1" check="at least one" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <object object_ref="oval:com.redhat.rhsa:obj:20091463003" />
 <state state_ref="oval:com.redhat.rhsa:ste:20091463008" />
</rpminfo_test>

 </tests>

 <objects>
   <!-- ~~~~~~~~~~~~~~~~~~~~   rpminfo objects   ~~~~~~~~~~~~~~~~~~~~ -->
<rpminfo_object id="oval:com.redhat.rhsa:obj:20091463003" version="302" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <name>newt-devel</name>
</rpminfo_object>
<rpminfo_object id="oval:com.redhat.rhsa:obj:20091463001" version="302" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <name>redhat-release</name>
</rpminfo_object>
<rpminfo_object id="oval:com.redhat.rhsa:obj:20091463002" version="302" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <name>newt</name>
</rpminfo_object>

 </objects>
 <states>
   <!-- ~~~~~~~~~~~~~~~~~~~~   rpminfo states   ~~~~~~~~~~~~~~~~~~~~~ -->
<rpminfo_state id="oval:com.redhat.rhsa:ste:20091463001" version="302" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <signature_keyid  operation="equals">219180cddb42a60e</signature_keyid>
</rpminfo_state>
<rpminfo_state id="oval:com.redhat.rhsa:ste:20091463002" version="302" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <signature_keyid  operation="equals">5326810137017186</signature_keyid>
</rpminfo_state>
<rpminfo_state id="oval:com.redhat.rhsa:ste:20091463003" version="302" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <version  operation="pattern match">^5[^[:digit:]]</version>
</rpminfo_state>
<rpminfo_state id="oval:com.redhat.rhsa:ste:20091463004" version="302" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <evr datatype="evr_string" operation="less than">0:0.52.2-12.el5_4.1</evr>
</rpminfo_state>
<rpminfo_state id="oval:com.redhat.rhsa:ste:20091463005" version="302" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <version  operation="pattern match">^3[^[:digit:]]</version>
</rpminfo_state>
<rpminfo_state id="oval:com.redhat.rhsa:ste:20091463006" version="302" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <evr datatype="evr_string" operation="less than">0:0.51.5-2.el3</evr>
</rpminfo_state>
<rpminfo_state id="oval:com.redhat.rhsa:ste:20091463007" version="302" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <version  operation="pattern match">^4[^[:digit:]]</version>
</rpminfo_state>
<rpminfo_state id="oval:com.redhat.rhsa:ste:20091463008" version="302" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux";>
 <evr datatype="evr_string" operation="less than">0:0.51.6-10.el4_8.1</evr>
</rpminfo_state>

 </states>
</oval_definitions>

======================================================
When I run this script, it ends with this error:
======================================================
$ perl -w test2.pl

creating parser object:
opening xsl...
opening document
Opening URL
preprocessing stylesheet...
Version for namespace `' = `1.0'
Namespace `ns1:' = `http://oval.mitre.org/XMLSchema/oval-definitions-5'
Namespace `xsl:' = `http://www.w3.org/1999/XSL/Transform'
Namespace `xs:' = `http://www.w3.org/2001/XMLSchema'
Default Namespace: `'
XSL Namespace: `xsl:'
Extracting variables
xsl output
output
xsl template
template
xsl template
template
xsl template
template
adding default templates to stylesheet
transforming document:
opening xml...
opening document
Opening URL
done...
processing project:
processing project:
matching template for "/" with count 1
      and path "":
  #6 "criteria" did not match
  #5 "criteria" did not match
  found #4 with "/" in "/"
Source

evaluating template content with current path "":
 XML::DOM::Text
 XML::DOM::Element
  evaluating element `apply-templates' from `':
   This is an xsl tag
   applying templates on children select of "":
getting node-set "oval_definitions/definitions/definition/criteria" from "/"
    using "/oval_definitions/definitions/definition/criteria":
     Trying /oval_definitions/definitions/definition/criteria >
getting element `oval_definitions' ("/definitions/definition/criteria")
       Trying /definitions/definition/criteria >
       getting element `definitions' ("/definition/criteria")
         Trying /definition/criteria >
         getting element `definition' ("/criteria")
           Trying /criteria >
           getting element `criteria' ("")
            node found!
selecting template oval_definitions/definitions/definition/criteria for child type XML::DOM::Element of "": matching template for "oval_definitions/definitions/definition/criteria" with count 1
      and path "/oval_definitions/definitions/definition/criteria":
           found #6 with "criteria" in "criteria"
evaluating template content with current path "/oval_definitions/definitions/definition/criteria[1]":
          XML::DOM::Text
          XML::DOM::Element
evaluating element `param' from `/oval_definitions/definitions/definition/criteria[1]':
            This is an xsl tag
            definition of variable $level:
evaluating template content with current path "/oval_definitions/definitions/definition/criteria[1]":
              done!
          XML::DOM::Text
          XML::DOM::Element
evaluating element `value-of' from `/oval_definitions/definitions/definition/criteria[1]':
            This is an xsl tag
getting node-set "concat('level : ', $level, ' ','[',local-name(.),']', generate-id(..), ' ', generate-id(.), ' ', 'operator="', @operator,'"')" from "/oval_definitions/definitions/definition/criteria[1]" using "/concat('level : ', $level, ' ','[',local-name(self::node()),']', generate-id(parent::node()), ' ', generate-id(self::node()), ' ', 'operator="', attribute::operator,'"')": Trying /concat('level : ', $level, ' ','[',local-name(self::node()),']', generate-id(parent::node()), ' ', generate-id(self::node()), ' ', 'operator="', attribute::operator,'"') > getting element `concat' ("('level : ', $level, ' ','[',local-name(self::node()),']', generate-id(parent::node()), ' ', generate-id(self::node()), ' ', 'operator="', attribute::operator,'"')")
               failed!
             stripping node to text:
             nothing left..
           XML::DOM::Text
           done!
        XML::DOM::Text
        done!
       done!
      done!
==============================================================
I don't know how to deal with it...
Could you help me pls?

There are my source files:
http://forstman.kvalitne.cz/temp/jezza/test2.pl
http://forstman.kvalitne.cz/temp/jezza/test2.xsl
http://forstman.kvalitne.cz/temp/jezza/com.redhat.rhsa-20091463.xml

THX FOR HLP.

Jezza


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to