473,320 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Understanding XPath in XSLT

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
Jul 20 '05 #1
13 2475
In article <bd**************************@posting.google.com >,
tfsquare <tf******@yahoo.com> 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!
Jul 20 '05 #2
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" <tf******@yahoo.com> wrote in message
news:bd**************************@posting.google.c om...
All,

I am new to XSLT and having some problems understanding the syntax of

Jul 20 '05 #3
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!
Jul 20 '05 #4
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!
Jul 20 '05 #5
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" <tf******@yahoo.com> wrote in message
news:bd**************************@posting.google.c 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

Jul 20 '05 #6
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!
Jul 20 '05 #7
In article <3f***********************@news.frii.net>,
First Last <tf******@yahoo.com> 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
pt**@interlog.com
Jul 20 '05 #8
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.

tf******@yahoo.com (tfsquare) wrote in message news:<bd**************************@posting.google. com>...
I'm hopelessly confused as to why various XPath's pick various nodes.
Any help you can provide is greatly appreciated.

Jul 20 '05 #9
tf******@yahoo.com (tfsquare) wrote in message news:<bd**************************@posting.google. 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
Jul 20 '05 #10
Baldo,
a main NODE is an "HAVE TO":

<ROOT>
<FOO>foo.top.level</FOO>
....
</ROOT>


When you say "HAVE TO" do you mean XSLT and/or XPath demands this,
perhaps as specified in a RFC? That would be interesting. Of course
my problem is trying to understand existing XPaths in the context of
existing XSL, XML and XPath expressions.

Thanks,
TFSquare
Jul 20 '05 #11
Patrick,
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.


No, no, if I posted _exactly_ what I'm doing, THAT would keep you up
at night, I know it does me :)
Jul 20 '05 #12
> When you say "HAVE TO" do you mean XSLT and/or XPath demands this,
perhaps as specified in a RFC? That would be interesting. Of course
my problem is trying to understand existing XPaths in the context of
existing XSL, XML and XPath expressions.


I think it's all about XML RFC.. try saving an XML file like that:

<root1>asd</root1>
<root2>asd</root2>

then open it with IE, NETSCAPE or OPERA (or any XML validator):

"XML parsing failed: junk after document element (Line: 2, Character:
0)

<root1>asd</root1>
<root2>asd</root2>"
--

If your problem is to understand existing XPaths in the context of
existing XML, you should test that XML is WELL FORMED..

Hope this is clear..
Jul 20 '05 #13
In article <bd*************************@posting.google.com> ,
tfsquare <tf******@yahoo.com> wrote:
% Baldo,
%
% > a main NODE is an "HAVE TO":
% >
% > <ROOT>
% > <FOO>foo.top.level</FOO>
% > ....
% > </ROOT>
%
% When you say "HAVE TO" do you mean XSLT and/or XPath demands this,
% perhaps as specified in a RFC? That would be interesting. Of course

XML and related technologies are defined in w3c recommendations (and
oasis specifications) rather than RFCs. The most important XML recommendation
is `Extensible Markup Language (XML) 1.0', which you can find at

http://www.w3.org/TR/REC-xml

The most important concept described in that recommendation is
well-formedness. The rules for a well-formed document are reasonably
simple (this is taken from the second edition, but I don't think the
wording changed in the third edition):

[Definition: A textual object is a well-formed XML document if:]
1. Taken as a whole, it matches the production labeled document.
2. It meets all the well-formedness constraints given in this
specification.
3. Each of the parsed entities which is referenced directly
or indirectly within the document is well-formed.

I'm not going to quote the document production because it doesn't stand on
its own, but the recommendation explicitly states some implications of
matching it:

Matching the document production implies that:
1. It contains one or more elements.
2. [Definition: There is exactly one element, called the root,
or document element, no part of which appears in the content of
any other element.] For all other elements, if the start-tag is
in the content of another element, the end-tag is in the content
of the same element. More simply stated, the elements, delimited
by start- and end-tags, nest properly within each other.

[Definition: As a consequence of this, for each non-root element C in
the document, there is one other element P in the document such that C
is in the content of P, but is not in the content of any other element
that is in the content of P. P is referred to as the parent of C, and
C as a child of P.]

The second implication is what's meant by `HAVE TO'. If you have more
than one top-level element, you have more than one XML document.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
7
by: Sebastian Petzelberger | last post by:
Hi group, please give me an example of a xpath with regex or better a link with examples. Thanks in advance, Sebastian
1
by: DV | last post by:
Hello, can anyone tell me or point me to somewhere what the exact differences (in terms of when would I use what) between XPath, XLink, XPointer and DOM are? Does it require special software...
14
by: inquirydog | last post by:
Hi- One frusterating thing for me with xsl is that I don't know how to make xslt throw some sort of exception when a value-of path does not exist. For instance, suppose I have the following...
1
by: Murtaza Tinwala | last post by:
Hi mates, I have the following problem in XSLT. I have following variables: ref-file = <path of XML document> eg "xmlDoc.xml" repeatpath = <a repeat path expressed in Xpath like /root/person >...
4
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a...
1
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT...
5
by: RolfK | last post by:
Dear ALL, I'm writing some first examples to get a better understanding of XSLT/ XPATH2.0. Please excute this code, any xml input is OK. I'm using saxon. The example runs perfect with ALTOVA,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.