File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes In XSLT , is reference to root node required to access child node of root node ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "In XSLT , is reference to root node required to access child node of root node ?" Watch "In XSLT , is reference to root node required to access child node of root node ?" New topic
Author

In XSLT , is reference to root node required to access child node of root node ?

nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 357
I have following xml file

In the xslt code created to acess student node, do I need to access it though root context as follows?


or can I access it without referencing root context ?


If not, then how can student node be accesses without reference to root node class as follows ?


This is given in an example in the tutorial on the net.

Please explain.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Explain what you have tried so far. There are a few different ways to program with XSLT.


This will fire when each student element is read.



Here you can iterate through all child student elements.
nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 357
1) To access an element in xml doc, do we not need to "select" root node first ? This is what I came across in the book "using xslt" by Michael Floyd



class is document node and student is child node of class.

If I want to access student node, do I not need to address class node first ? I was reading an article which stated " every xslt doc must have a root node"


In this case root node is addressed.



In this xslt code, root node is not addressed. Is this correct ?


Again, in this code, root node is not addressed. So will this code work ? If yes, then does it mean that addressing the root node syntax is not required ?

Please explain the rule for root node , when is it required to address the root node and when not.

2) I tried to use these codes in Awgar stone xslt processor. But when I select the xml , xslt and output files and select to transform , I get an error message
"The version attribute is required at this location.

Line 1 : <?xml encoding="UTF-8" version="1.0"?>."

I am not sure, why do I get this error. I could not test it at my end.

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
...I was reading an article which stated " every xslt doc must have a root node"




Yes, this is correct. Every XLST document must have a root node. In the document above the root node is the stylesheet element.
nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 357
what I was asking is about the root node of the xml document that is being transformed. Does an xslt not need to address root node of xml doc to access children nodes ?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Have you tried this out to find the answer to your question? If you don't process the root node, can you still process the contents of the root node?
nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 357
I am unable to test it on my end. Please my read post , I have mentioned that I am getting error while using xslt procesor and that also is a problem. Why am I getting such error ?

thanks
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Why do you feel that you are unable to test this? All you need is a copy of Internet Explorer. IE has a built-in XSLT processor.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: In XSLT , is reference to root node required to access child node of root node ?
 
Similar Threads
A doubt about Xpath expression
is it possible?
How to count ?
XSLT/XPath - Find unique text node value
XSLT Calculations