How to get Full XML in a xsl:variable

Hi Experts,

 I have an xml as :

 <TestNode1 name="node1"> This is test node 1</TestNode1>
 <TestNode2 name="node2"> This is test node 2</TestNode2>

My Question :

 Is this possible to get this XML in a xsl:variable ?

 When I use <xsl:variable name="nodes" select="/"/> it gives me just the contents not the nodes.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It should be no problem. It works fine at least in MSXSL:
<xsl:variable name="nodes" select="/"/>
<xsl:for-each select="$nodes/Test/*">
<xsl:value-of select="name()"/> - <xsl:value-of select="."/>,

Open in new window

sanjeev_mcaAuthor Commented:
That's true, but when i pass this variable to a Java method, it looses its tags and only contents are passed.
I don't know how to pass an XSL variable to Java. It does not make sense to me. You should try to ask your question in a related zone Java.
But if you meant a JavaScript embedded in the XSLT, then it's different.
Look at the following sample. The xslt passes the variable the the script and the script sees it as a tree, an is able to recursively enumerate all its nodes.
<xsl:stylesheet exclude-result-prefixes="msxsl js"
      xmlns:js="" version="1.0">
<xsl:output method="xml" indent="yes" encoding="iso-8859-1"/>
<msxsl:script language="JScript" implements-prefix="js">

   function e( n ) {
      var s="["+n.nodeName+"]\n";
      for( var i=0; i < n.childNodes.length; i++ ) 
        if( n.childNodes.item(i).nodeType==1 )
      		s+=e( n.childNodes.item(i) );
      return s;

   function f( n ) {
      var h = "" + e( n.item(0).documentElement );
      return h;


<xsl:template match="/">
	<xsl:variable name="nodes" select="/"/>
	<xsl:value-of select="js:f($nodes)"/>


Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.