Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

xml::twig and stylesheets

by rogue90 (Novice)
on Mar 22, 2006 at 17:21 UTC ( #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? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2023-06-02 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?