Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: I don't understand the scope of accessing XML elements... I don't understand the scope of accessing XML elements...To: NULL Date: 6/5/2008 7:05:00 AM I am having some trouble understanding the scope of the XML that's
passed to an XSL document.
Let me provide an example. Say I have an XML document like this:
<?xml version="1.0" encoding="utf-8"?>
<blog xmlns="">
<blogPosts>
<blogPost id="47">
<title>Blog post 1</title>
<author>Brian</author>
<date>2008/06/04</date>
<body>This is my first blog post</body>
</blogPost>
<blogPost id="52">
<title>Blog post 2</title>
<author>Robert</author>
<date>2008/06/05</date>
<body>Second blog post.</body>
</blogPost>
</blogPosts>
</blog>
And in my C# .NET code I've got this:
XPathExpression path = XPathExpression.Compile("//blogPost[@id=47]");
When I pass it through an XSL transform, I can only access the child
elements of my blogPost as "//title", "//author", "//body", and so
forth. This seems imprecise to me, because if I happened to have an
element of the same name nested deeper in the blogPost element, it
might pick up the wrong element instead. But I don't understand why I
can't simply refer to the child elements as "title", "author", and
"body" - I don't know why the XSL simply doesn't see them.
So, when I select part of an XML tree by compiling an XPathExpression,
what does the resultant XSL transform actually see?
- Does it see a tree whose root is '/blog/blogPosts/
blogPost[id="47"]'? Should I be referencing the child elements as "/
title", "/author"...?
- Or does it see the entire XML tree, so if I refer to "//title"
there's a chance it might pick up the title of the wrong blogPost?
I apologize if I'm not describing this well, but I'm having a hard
time grasping it. Any help clarifying it would be greatly appreciated.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
