Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5984427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:22:27+00:00 2026-05-22T22:22:27+00:00

I have a XML created dynamically. However, I want to add a reference to

  • 0

I have a XML created dynamically. However, I want to add a reference to an XSLT file in it, to be able to render the XML file as HTML in Mozilla.

I want my final XML to start something like this:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="xslt_stylesheet_file.xsl"?>
<root_node>
</root_node>

I am not able to install XML::LibXSLT, so that is not a solution.
Another solution would be to write the XML in a file, open it as a regular file and add the XSLT reference to it – but that just doesn’t seem right to me.

Are there elegant solutions to this?

Edit:

Added some code

use strict;
use warnings;
use XML::LibXML;

my $final_xml = XML::LibXML::Document->new('1.0','utf-8');

 my $root_node = $final_xml->createElement('root'); 

 $final_xml->setDocumentElement( $root_node );


open (MYFILE, '>final.xml' );
 print MYFILE $final_xml->toString();
close (MYFILE);

And the output is:

<?xml version="1.0" encoding="utf-8"?>
<root/>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:22:28+00:00Added an answer on May 22, 2026 at 10:22 pm
    use strict;
    use warnings;
    use XML::LibXML;
    
    my $final_xml = XML::LibXML::Document->new('1.0','utf-8');
    
    my $pi = $final_xml->createProcessingInstruction("xml-stylesheet");
    $pi->setData(type=>'text/xsl', href=>'xslt_stylesheet_file.xsl');
    $final_xml->appendChild($pi);
    
    my $root_node = $final_xml->createElement('root'); 
    $final_xml->setDocumentElement($root_node);
    
    $final_xml->toFile("final.xml")
    

    =>

    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet href="xslt_stylesheet_file.xsl" type="text/xsl"?>
    <root/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have an empty XML file like so: <root></root> And I want
I have created a spark ButtonBar which is dynamically populated with XML and skinned
Actually I have created a custom ListView . I want to add items to
Using WiX (Windows Installer XML) I have created an MSI installer which installs Word
I have an expression tree I have created by parsing an Xml using the
I have xml files I want to read in and store in the database.
I have a PHP script that loads XML content dynamically: require_once 'directory/directory/'; $nice= '1149632';
I have a TabControl with dynamically created tabs and content that vary depending on
I have created an XML document with the following contents. <books> <book id=1> <title>Title01</title>
I have created custom build tasks in my project file to run my nUnit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.