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

  • SEARCH
  • Home
  • 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
  • 1 View
  • 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

I have some Dynamically created XML file present in my Document directory.So i want
I have an XML file (dynamically created) and an XSL style sheet; if I
I have a dynamically created xml file that contains a record with five descriptor
I have created XML file,but I can't view it/output it.I know there is no
I have an XML document as follows: <directory> <file><monitored>0</monitored> <xferStatus>1</xferStatus> <name>test1.txt</name> <size>7</size> <created>03/31/10 11:30:02
I have created the following vsct file xml. <?xml version=1.0 encoding=utf-8?> <CommandTable xmlns=http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable xmlns:xs=http://www.w3.org/2001/XMLSchema>
I have created a xslt document which formats an xml document, but I would
I have dynamically created a xml string form a JSON object returned from server.
I have loaded some images through XML and attached into dynamically created MovieClips named
I have created a spark ButtonBar which is dynamically populated with XML and skinned

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.