Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

xml::twig and stylesheets

by rogue90 (Novice)
on Mar 22, 2006 at 17:21 UTC ( [id://538550]=perlquestion: print w/replies, xml ) Need Help??

rogue90 has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to add a xml-stylesheet reference in xml twig? I've searched long and far yet the answer eludes me. Using twig v3.22

Replies are listed 'Best First'.
Re: xml::twig and stylesheets
by mirod (Canon) on Mar 22, 2006 at 18:49 UTC

    What is an "xml-stylesheet reference" exactly?

    If you mean a processing that attaches an xsl stylesheet (eg <?xml-stylesheet type= "text/xls" href="xls_style.xlss"?>, then it's a processing instruction, and can be inserted as a regular PI: create an element with a tag of '#PI' and set its target to xml-stylesheet (using set_target) and its data to type= "text/xls" href="xls_style.xlss" (using set_data).

    Does this help?

      how do I get the PI to appear at the beginning of the document?
      my $xsl = new XML::Twig::Elt('#PI'); $xsl->set_target('xml-stylesheet'); $xsl->set_data('type= "text/xls" href="xls_style.xls"'); $xsl->paste('before', $twig->root);
      This fails because you can't paste before the root.

        Now you are entering the dark realm of comments and processing instructions before and after the root... be afraid, very afraid!

        The answer: you have to replace the paste by $twig->_add_cpi_outside_of_root( leading_cpi => $xsl);. Which I agree is slightly weird, not to mention totally undocumented.

        This might actually be worth a method of its own. What about add_stylesheet( $stylesheet_url )?

      Yep! I wasn't sure what a PI was. Thanks for your help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://538550]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-10-07 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (44 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.