How to get Full XML in a xsl:variable

Hi Experts,

 I have an xml as :

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

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.

Thanks!
Sanjeev
LVL 1
sanjeev_mcaAsked:
Who is Participating?
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.

zc2Commented:
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="."/>,
</xsl:for-each>

Open in new window

0
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.
0
zc2Commented:
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:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:js="http://mycompany.com/mynamespace" version="1.0">
      
<xsl:output method="xml" indent="yes" encoding="iso-8859-1"/>
<msxsl:script language="JScript" implements-prefix="js">
<![CDATA[

   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) );
      s+="[/"+n.nodeName+"]\n";
      return s;
   }

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

]]>
</msxsl:script>

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

   
</xsl:stylesheet>

Open in new window

0

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.