Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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 .
Reply With Quote
  #2 (permalink)  
Old March 8th, 2010, 03:30 AM
Authorized User
 
Join Date: Feb 2009
Location: Gurgaon
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
Reply With Quote
  #3 (permalink)  
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 ?
Reply With Quote
  #4 (permalink)  
Old March 8th, 2010, 09:23 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
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
Reply With Quote
  #5 (permalink)  
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 ?
Reply With Quote
  #6 (permalink)  
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:45 PM.


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