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 6033935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:33:20+00:00 2026-05-23T05:33:20+00:00

With the following script I rename the elements through XSLT of an XML and

  • 0

With the following script I rename the elements through XSLT of an XML and output the result. However I want to save it in a new file on my browser but the only I managed to do is to save the input XML.

<?php

// create an XSLT processor and load the stylesheet as a DOM 
$xproc = new XsltProcessor();
$xslt = new DomDocument;
$xslt->load('stylesheet.xslt');    // this contains the code from above
$xproc->importStylesheet($xslt);


// your DOM or the source XML (copied from your question)
$xml = '<document><item><title>Hide your heart</title><quantity>1</quantity><price>9.90</price></item></document>';
$dom = new DomDocument;
$dom->loadXML($xml);

// do the transformation
if ($xml_output = $xproc->transformToXML($dom)) {
    echo $xml_output;
} else {
    trigger_error('Oops, XSLT transformation failed!', E_USER_ERROR);
} 

?>

I used

echo $dom->saveXML();
$dom->save("write.xml")

and replaced it with xml_output with no luck.

  • 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-23T05:33:21+00:00Added an answer on May 23, 2026 at 5:33 am
    if ($xml_output = $xproc->transformToDoc($dom)) {
      $xml_output->save('write.xml');
    } else {
      trigger_error('Oops, XSLT transformation failed!', E_USER_ERROR);
    }
    

    transformToXML() returns a string instead of a DOMDocument. You can also write the string to a file using the common file handling functions

    if ($xml_output = $xproc->transformToXML($dom)) {
      echo $xml_output;
      file_put_contents('write.xml', $xml_output);
    } else {
      trigger_error('Oops, XSLT transformation failed!', E_USER_ERROR);
    } 
    

    Update: Just found the third method 🙂 Depending on what you want to achieve this is the one you are looking for

    $xproc->transformToURI($doc, 'write.xml');
    

    http://php.net/xsltprocessor.transformtouri

    You can find the signature of the whole class at the manual: http://php.net/class.xsltprocessor

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following Script isn't working in CHROME browser, IE is Fine. I've changed opener.document ...
The following script creates symlinks as expected, but the original file can never be
I want to rename a bunch of files using bash, transforming this file pattern:
For simplicity, i have the following file named test.jsp: <script language=javascript> alert(a$b.replace(/\$/g,k)); </script> I
I have hundreds of file of same format. I want to rename the files
People claim the following VB script works for changing network adapter names. However I
Here is my batch file rename and move script so far import os, re,
The following script: cls function test_me([string]$testVar, $my_array) { Write-Host $testVar } $test_array = a,b
The following script was recommended to use a List Page to show a Google
The following script works for me, but I wonder if it could be done

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.