Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Thu, 5 Jun 2008 07:04:50 -0700 (PDT),    group: microsoft.public.xsl        back       


I don't understand the scope of accessing XML elements...   
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.
date: Thu, 5 Jun 2008 07:04:50 -0700 (PDT)   author:   Brian Kendig

Re: I don't understand the scope of accessing XML elements...   
Brian Kendig wrote:
> 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?

I can't follow you. Usually if you have an XPathExpression object, then 
you don't use it with XSLT but rather with the XPathNavigator API where 
you can pass in an XPathExpression to the Select or SelectSingleNode method.
If you are doing something else then please show us the relevant code to 
enable us to understand how exactly you use XPathExpression.




-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Thu, 05 Jun 2008 16:47:56 +0200   author:   Martin Honnen

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us