XML::LibXSLT element tags stripped out

Discussion in 'Perl Misc' started by Abro Gaticus, Mar 22, 2005.

  1. Abro Gaticus

    Abro Gaticus Guest

    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:eek:utput
    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:eek:utput 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');
    Abro Gaticus, Mar 22, 2005
    #1
    1. Advertising

  2. Abro Gaticus wrote:

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


    It is, and not a Perl one - it is a pure XSL one.

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


    This is the effect of the default XSL trasformation.

    > <xls:eek:utput
    > method="xml"/> is ignored. I find this strange as I have read
    > documentation that 'xml' should be the default output method anyway.


    AFAIK, it is.

    > Perhaps someone can suggest what I am doing incorrectly.


    You are wrongly assuming that the default XSL transformation is the
    identity transformation.

    Read about the default XSL tranformation here:

    http://www.w3.org/TR/xslt#built-in-rule

    If you want to copy elements you need to add an explicit template to do so.

    http://www.w3.org/TR/xslt#copying
    Brian McCauley, Mar 23, 2005
    #2
    1. Advertising

  3. Abro Gaticus

    Abro Gaticus Guest

    Thank you very much kind sir! Spot on!

    -Abro
    Abro Gaticus, Mar 23, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Iain
    Replies:
    2
    Views:
    667
  2. Johannes Busse

    libxslt: compiled xml representation?

    Johannes Busse, Feb 2, 2005, in forum: XML
    Replies:
    0
    Views:
    467
    Johannes Busse
    Feb 2, 2005
  3. Chris Chamberlain

    X-MicrosoftAjax header being stripped out by firewalls

    Chris Chamberlain, Sep 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    610
  4. Iain
    Replies:
    1
    Views:
    149
    Martin Honnen
    Dec 15, 2003
  5. geed_dd
    Replies:
    2
    Views:
    132
    geed_dd
    Jun 8, 2006
Loading...

Share This Page