Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Understanding XPath in XSLT

Reply
Thread Tools

Understanding XPath in XSLT

 
 
tfsquare
Guest
Posts: n/a
 
      12-02-2003
All,

I am new to XSLT and having some problems understanding the syntax of
XPath which selects nodes in the XML document. Consider this bit of
XML, which contains three outer XML elements.

<FOO>foo.top.level</FOO>
<BOO><FOO>foo.second.level</FOO></BOO>
<CHOO><BOO><FOO>foo.third.level</FOO></BOO></CHOO>

My testing shows
(a) "/*/FOO" results in a empty string
(b) "//FOO" results in "foo.top.level"
(c) "/FOO" results in a empty string
(d) "//*/FOO" results in "foo.top.level"
(e) "//*/*/FOO" results in "foo.top.level"
(f) "//BOO/FOO" results in "foo.second.level"

I'm picking up the results like this...

<xsl:variable name="foo1" select="/*/FOO"/>

I'm hopelessly confused as to why various XPath's pick various nodes.
Any help you can provide is greatly appreciated.

Thanks,
TFSquare
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      12-02-2003
In article <(E-Mail Removed) >,
tfsquare <(E-Mail Removed)> wrote:

>I am new to XSLT and having some problems understanding the syntax of
>XPath which selects nodes in the XML document. Consider this bit of
>XML, which contains three outer XML elements.


An XML document can't contain three outer elements, so I'm surprised
you're not getting an error. What exactly are you doing?

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
 
Reply With Quote
 
 
 
 
Toni Uusitalo
Guest
Posts: n/a
 
      12-02-2003
Good xml (and related) tutorials can be found here:
http://www.zvon.org
(click tutorials and XPATH TUTORIAL for example)

with respect,
Toni Uusitalo

"tfsquare" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> All,
>
> I am new to XSLT and having some problems understanding the syntax of



 
Reply With Quote
 
First Last
Guest
Posts: n/a
 
      12-02-2003
Toni,

>> Good xml (and related) tutorials can be found here:

http://www.zvon.org<<

Thanks, I'll check that out.
TFSquare.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
First Last
Guest
Posts: n/a
 
      12-02-2003
Richard,

Thanks for the reply.

>>An XML document can't contain three outer elements, so I'm surprised

you're not getting an error. What exactly are you doing?<<

True, but XSLT can process a stream of 'multiple XML documents'. Here
is a quote from Michael Kay's XSLT 2nd Edition, page 358.

"If you are writing a stylesheet that loads several source douments
using the document() function, there is no direct way of selecting *the
root of the principal source document* when the context node is a
different one."

The fog is slowly clearing as I read more and try various XPath's to see
what they do, but I've got a ways to go yet. In my example, I now see
part of the problem was the "context" node was set to a place I hadn't
expected.

In regards to your question: What exactly am I doing? I'm processing a
stream of mini-XML documents (I think of them as small objects) to
through a XSL stylesheet to produce HTML output.

Thanks,
TFSquare

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Dimitre Novatchev
Guest
Posts: n/a
 
      12-02-2003
A good book on XPath will help. I can also recommend the XPath Visualizer --
a tool that helps learn XPath through many practical exercises and in a fun
way.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


"tfsquare" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> All,
>
> I am new to XSLT and having some problems understanding the syntax of
> XPath which selects nodes in the XML document. Consider this bit of
> XML, which contains three outer XML elements.
>
> <FOO>foo.top.level</FOO>
> <BOO><FOO>foo.second.level</FOO></BOO>
> <CHOO><BOO><FOO>foo.third.level</FOO></BOO></CHOO>
>
> My testing shows
> (a) "/*/FOO" results in a empty string
> (b) "//FOO" results in "foo.top.level"
> (c) "/FOO" results in a empty string
> (d) "//*/FOO" results in "foo.top.level"
> (e) "//*/*/FOO" results in "foo.top.level"
> (f) "//BOO/FOO" results in "foo.second.level"
>
> I'm picking up the results like this...
>
> <xsl:variable name="foo1" select="/*/FOO"/>
>
> I'm hopelessly confused as to why various XPath's pick various nodes.
> Any help you can provide is greatly appreciated.
>
> Thanks,
> TFSquare



 
Reply With Quote
 
First Last
Guest
Posts: n/a
 
      12-02-2003
Dimitre,

>>http://fxsl.sourceforge.net/ -- the home of FXSL<<


I'm reading this right now -- this is very helpful.

Thanks again,
TFSquare.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Patrick TJ McPhee
Guest
Posts: n/a
 
      12-02-2003
In article <3fcce5f5$0$88382$(E-Mail Removed)>,
First Last <(E-Mail Removed)> wrote:

% In regards to your question: What exactly am I doing? I'm processing a
% stream of mini-XML documents (I think of them as small objects) to
% through a XSL stylesheet to produce HTML output.

That's vaguely what you're doing. We're all curious to know
_exactly_ what you're doing. i.e., show us some XSLT or we'll
be losing sleep from wondering.


--

Patrick TJ McPhee
East York Canada
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Finnbarr P. Murphy
Guest
Posts: n/a
 
      12-03-2003
Have a look at Dimitre Novatchev's XPath Visualizer tool which
is available at www.vbxml.com/xpathvisualizer/default.asp
It's a good easy-to-use (and free) tool for learning the nuances
of XPath.

- Finnbarr

This is a full blown Visual XPath Interpreter for the evaluation of
any XPath expression
and visual presentation of the resulting nodeset or scalar value.

(E-Mail Removed) (tfsquare) wrote in message news:<(E-Mail Removed). com>...

> I'm hopelessly confused as to why various XPath's pick various nodes.
> Any help you can provide is greatly appreciated.
>

 
Reply With Quote
 
Baldo
Guest
Posts: n/a
 
      12-03-2003
(E-Mail Removed) (tfsquare) wrote in message news:<(E-Mail Removed). com>...
> All,
>
> I am new to XSLT and having some problems understanding the syntax of
> XPath which selects nodes in the XML document. Consider this bit of
> XML, which contains three outer XML elements.
>
> <FOO>foo.top.level</FOO>
> <BOO><FOO>foo.second.level</FOO></BOO>
> <CHOO><BOO><FOO>foo.third.level</FOO></BOO></CHOO>


a main NODE is an "HAVE TO":

<ROOT>
<FOO>foo.top.level</FOO>
<BOO>
<FOO>foo.second.level</FOO>
</BOO>
<CHOO>
<BOO>
<FOO>foo.third.level</FOO>
</BOO>
</CHOO>
</ROOT>

select="root/foo" --> top
select="root/boo/foo" --> second
select="root/choo/boo/foo" --> third

select="//foo" --> top, second, third
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
Problem understanding what XPATH to write Clarence XML 4 10-06-2004 02:50 PM
Are there any XPath parsers that generate XPath trees? goog XML 0 01-14-2004 01:47 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments