Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From within a xslt, can you output the entire XML?

Tags:

c#

xml

asp.net

xslt

Inside my XSLT that is transforming a order XML, I want to dump the entire XML I am currently working with. How can I do this?

I am weaving some HTML based on XML, and want to dump the entire XML into a textarea.

like image 921
Blankman Avatar asked Apr 16 '10 18:04

Blankman


People also ask

What are the output formats for XSLT?

XSLT uses the <xsl:output> element to determine whether the output produced by the transformation is conformant XML (<xsl:output method="xml"/> ), valid HTML (<xsl:output method="html"/> ), or unverified text (< xsl:output method="text"/> ).

What is the output of an XSLT processor?

An XSLTProcessor applies an XSLT stylesheet transformation to an XML document to produce a new XML document as output.

How do I convert one XML to another XML using XSLT?

The standard way to transform XML data into other formats is by Extensible Stylesheet Language Transformations (XSLT). You can use the built-in XSLTRANSFORM function to convert XML documents into HTML, plain text, or different XML schemas. XSLT uses stylesheets to convert XML into other data formats.

Can XML be transformed on client side?

Client-side transformation with XSLT As is illustrated below, with your XML document open in <oXygen>, go to the Document menu and select XML Document, then Associate XSLT/CSS Stylesheet. Change to the XSLT tab, click on the little folder icon to the right of the text input box, and pick your XSLT file.


2 Answers

Probably the shortest ... :)

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
  <xsl:copy-of select="."/>
 </xsl:template>
</xsl:stylesheet>
like image 159
Dimitre Novatchev Avatar answered Oct 01 '22 03:10

Dimitre Novatchev


So you want to produce a <textarea> element, and dump everything into that element?

Then you can use something like:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="/">
      <textarea>
         <xsl:copy-of select="/" />     
      </textarea>
   </xsl:template>  
</xsl:stylesheet>

Be careful: The output won't be escaped!

Or put the <xsl:copy-of> wherever you produce the textarea.

Small note, if you have to work on really large XML files: If you call the copy-of from a template that matches somewhere deeper in the hierarchy, this can slow down the xslt processor, because it must "jump" outside of the local node. So, the xslt processor can't use certain optimizations.

like image 25
Chris Lercher Avatar answered Oct 01 '22 02:10

Chris Lercher