Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


I don't understand the scope of accessing XML elements...

From: Brian Kendig <brian@---------.--->
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.



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent