Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2010, 03:16 AM
Authorized User
 
Join Date: Dec 2009
Posts: 23
Thanks: 3
Thanked 0 Times in 0 Posts
Default What is the best approch to find root element ?

Hi we have many xml file as input and we processed each one by one.Now for each xml we need to find root element and based on this we need to take decision how to process that xml accordingly.

Before this we are using DocumentBuilder's parse method to get Document object and then using getDocumentElement() of Document object to get root element .Now we find that when file is large then it throws out of memory error ?

So we need to find out that is it possible through xslt ? or we need to apply code that will parse whole xml and find root element ?

Can anybody pls help me ?

Thanks in Advance .
 
Old March 8th, 2010, 03:30 AM
Authorized User
 
Join Date: Feb 2009
Posts: 31
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to anil_yadav26@hotmail.com
Smile

You can find the root name like this:

Code:
 <xsl:template match="/">
     <xsl:value-of select="name(node())"/>
 </xsl:template>
Regards,
Anil Yadav
 
Old March 8th, 2010, 08:38 AM
Authorized User
 
Join Date: Dec 2009
Posts: 23
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thanks a lot for reply.

I got the Root Node with the help of that xslt code.

Can i store this value with xslt and return to code which perform Transformation ?
 
Old March 8th, 2010, 09:23 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

You can declare a global variable as below and use it any where inside the code:

Code:
<xsl:variable name="root" select="document(document-uri(.))/*[1]/name()"/>
 
<xsl:template match="/">
<xsl:value-of select="$root"/>
</xsl:template>
__________________
Rummy
 
Old March 8th, 2010, 09:41 AM
Authorized User
 
Join Date: Dec 2009
Posts: 23
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Can i access this value outside the xslt ?
 
Old March 11th, 2010, 07:25 AM
Authorized User
 
Join Date: Dec 2009
Posts: 23
Thanks: 3
Thanked 0 Times in 0 Posts
Default Solved problem with the use of StAX

Hi ,
I have solved my problem with StAX parser which stop the parsing when we get desire data.

Thanks a lot.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 7 re hiding root element in TreeView control stephjnca BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 May 27th, 2009 02:26 PM
Cannot find sub element riffla XSLT 2 March 17th, 2008 08:47 AM
root element missing Kross Classic ASP Basics 1 February 5th, 2007 08:16 AM
SiteMapDataSource won't find my root node... thenoseknows ASP.NET 2.0 Professional 0 October 31st, 2006 04:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.