tags:

views:

57

answers:

4

Inside my XSLT that is transfomign a order XML, I want to dump the entire XML I am currently working with.

Is this possible?

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

A: 
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
gbogumil
+5  A: 

Probably the shortest ... :)

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

 <xsl:template match="/">
  <xsl:copy-of select="."/>
 </xsl:template>
</xsl:stylesheet>
Dimitre Novatchev
@Dimitre: +1 that's probably really the shortest. ;) P.S.: On your way to 10k points, not much missing! :)
Tomalak
do you need the method=xml attribute in the output?
Blankman
omit-xml-declaration="yes" is going to omit the xml tags? i want them! :)
Blankman
@Tomalak: Thanks, I am following your path... :)
Dimitre Novatchev
@Blankman: The "xml" method is the default, you may adjust the `<xsl:output>` instruction according to your taste.
Dimitre Novatchev
Hmm..it seems to be showing up encoded in the email, not sure if its the xml processing or something else doing it.
Blankman
A: 

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"&gt;
   <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.

Chris Lercher
+1  A: 
<xsl:copy-of select="."/>
eglasius