Click here to get back home

XML::LibXSLT element tags stripped out of transformation

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
XML::LibXSLT element tags stripped out of transformation Abro Gaticus 03-21-2005
Posted by Abro Gaticus on March 21, 2005, 6:32 pm
Please log in for more thread options


Being extremely new to XML::LibXSLT and XML/XSL in general I have what
I am assuming is a very newb question.

I found an old post (dated 2001) that showed where to find ppm packages
for libXSLT since I am trying this out using activestate on XP.

C:> ppm
ppm> set repository RK http://theoryx5.uwinnipeg.ca/p­pmpackages/
ppm> set save
ppm> install XML::LibXML
ppm> install XML::LibXSLT

following these explicit instructions (much appreciated) I was able to
install the packages and begin scripting. The ppm packages are great
as they even download the dll's that XML::LibXSLT depends on.

I created a simple XML file, a simple XSL file, and a simple perl
script that uses XML::LibXSLT to perform the transformation.
Everything seems to work correctly except that in the result document
none of the element tags are output, only their values. <xls:output
method="xml"/> is ignored. I find this strange as I have read
documentation that 'xml' should be the default output method anyway.

Perhaps someone can suggest what I am doing incorrectly. Code below:
Thanks in advance.
---------------------------------------
test.xml:
<?xml version="1.0" ?>

<entry>
        <major>
                pain in the grass
        </major>
        <stats>
                <a> 11 </a>
                <b> 21 </b>
                <c> 31 </c>
                <d> 41 </d>
                <e> 51 </e>
        </stats>
</entry>

--------------------------------------
template.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml"/>

        <!-- first attempt -->
        <xsl:template match="stats">
                <xsl:text> Stats: </xsl:text>
                <xsl:apply-templates/>
        </xsl:template>

</xsl:stylesheet>
---------------------------------------
result.xml
<?xml version="1.0"?>


                pain in the grass

         Stats:
                 11
                 21
                 31
                 41
                 51
---------------------------------------
xslTest.pl
use strict;
use XML::LibXSLT;
use XML::LibXML;

my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();

my $source = $parser->parse_file('test.xml');
my $style_doc = $parser->parse_file('template.xsl');

my $stylesheet = $xslt->parse_stylesheet($style_doc);

my $results = $stylesheet->transform($source);

$stylesheet->output_file($results,'result.xml');



Posted by Brian McCauley on March 23, 2005, 12:00 pm
Please log in for more thread options


Abro Gaticus wrote:

[ exactly the same thing he wrote in .misc ]

Please do not do that. If a thread belongs in two newsgroups then
cross-post it. Do not start two separate threads and potentially waste
people's time by having them respond in one thread with stuff that's
already mention in the other.

But since the definition of being on-topic in .misc is Perl realated
stuff that doesn't fit into one of the other clp groups it cannot
(except in a few very special cases) be appropriate to crosspost.



Posted by Abro Gaticus on March 23, 2005, 8:46 am
Please log in for more thread options


My sincere apologies.

I was under the misconception that my post in clpm had failed and
decided this group might be a better fit on my second attempt. In the
future I will be more careful. Thanks!

-Abro



Similar ThreadsPosted
Name for fast data transformation module? July 28, 2007, 3:08 pm
Stripped module October 18, 2006, 1:08 pm
XML::LibXSLT, can't loadLibXSLT.dll March 17, 2005, 10:30 am
Re: match nested tags May 3, 2006, 5:20 pm
how to check for existenceof XML tags with XML::Simple? January 29, 2005, 12:45 pm
How to text in HTML::Element October 23, 2004, 7:31 pm
Extracting value from data within an element. November 30, 2005, 5:26 am
How to *modify* text in HTML::Element October 23, 2004, 8:16 pm
perl xml check for element closure November 18, 2006, 9:26 pm
HTML::Element->right/->look_down lose, I need to walk the tree June 20, 2005, 9:56 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap