Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to XSLT to echo out the XML powering it?

I am using XSLT to transform XML. Is there a way for the XSLT to spit out the XML that is feeding it? Something like:

<xsl:echo-xml />
like image 531
Andrew G. Johnson Avatar asked Jun 21 '10 20:06

Andrew G. Johnson


2 Answers

Basically I am using some XSLT to transform XML, is there a way for the XSLT to spit out the XML that is feeding it? Something like:

The easiest and shortest way:

<xsl:copy-of select="/"/>

This outputs the current XML document.

<xsl:copy-of select="."/>

This outputs the subtree rooted by the current node.

However, XSLT programmers use mostly the following (identity rule):

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

When this is the only template in the stylesheet, the complete XML document on which the transformation is applied is output as result.

Using the identity rule is one of the most fundamental XSLT design patterns. It makes extremely easy such tasks as copying all nodes but specific ones for which a specific processing is performed (such as renaming deleting, modifying the contents, ..., etc)/

like image 175
Dimitre Novatchev Avatar answered Nov 15 '22 12:11

Dimitre Novatchev


The following copies the full XML to the result tree:

<xsl:copy-of select="." />

If you want to send that to the "message output", you can just wrap this like that:

<xsl:message>
    <xsl:copy-of select="."/>
</xsl:message>
like image 26
Lucero Avatar answered Nov 15 '22 12:11

Lucero