473,320 Members | 2,110 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.

ancestor:: XML syntax


Is anyone familar with the correct syntax for using ancestor:: ?

I am trying to use it in a c# application, and I am also testing it in a
parser application called Cooktop ( http://www.xmlcooktop.com )

I cannot get it or my c# code to return a node list when using ancestor.
Is ancestor:: something that .NET does or does not support?

Examples, none of these work:

nodes://pallet/ancestor::position
<!--nodes xpath //pallet/ancestor::position'-->
<!--nodes xpath parent::*/pallet/position/*'-->
<!--nodes xpath parent::*//pallet/position/*'-->
<!--nodes xpath /ancestor::position/client[@id='MDR']'-->
<!--nodes xpath /pallet/ancestor::position/client[@id='MDR']'-->
<!--nodes xpath /pallet/position/ancestor::client[@id='MDR']'-->

for
<pallet>
<position row="0" bay="0" level="A">
<client id="HAL">
<partnum id="HA0132-1033 " isStock="N">HA0132-1033 </partnum>
<partnum id="HA9027EP " isStock="Y">HA9027EP </partnum>
</client>
<client id="MDR">
<partnum id="A/P FILES " isStock="N">A/P FILES </partnum>
</client>
<client id="OPS">
<partnum id="OPS " isStock="N">OPS
</partnum></client>
</position>
<position row="1" bay="1" level="B">
<client id="MDR">
<partnum id="A/P FILES " isStock="N">A/P FILES
</partnum>
</client>
</position>
<position row="1" bay="1" level="D">
<client id="MDR">
<partnum id="X-MAS DECORATION" isStock="N">X-MAS DECORATION
</partnum>
</client>
</pallet>
May 25 '06 #1
11 2490


John Bailo wrote:

Examples, none of these work:

nodes://pallet/ancestor::position
<pallet>
<position row="0" bay="0" level="A">
<client id="HAL">
<partnum id="HA0132-1033 " isStock="N">HA0132-1033 </partnum>
<partnum id="HA9027EP " isStock="Y">HA9027EP </partnum>
</client>
<client id="MDR">
<partnum id="A/P FILES " isStock="N">A/P FILES </partnum>
</client>
<client id="OPS">
<partnum id="OPS " isStock="N">OPS
</partnum></client>
</position>
<position row="1" bay="1" level="B">
<client id="MDR">
<partnum id="A/P FILES " isStock="N">A/P FILES
</partnum>
</client>
</position>
<position row="1" bay="1" level="D">
<client id="MDR">
<partnum id="X-MAS DECORATION" isStock="N">X-MAS DECORATION
</partnum>
</client>
</pallet>


The position elements are children of the pallet element so I don't
understand why you want
//pallet/ancestor::position
If you want to access the position elements then you need
/pallet/position
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 25 '06 #2
Martin Honnen wrote:

The position elements are children of the pallet element so I don't
understand why you want
//pallet/ancestor::position
If you want to access the position elements then you need
/pallet/position


So, I want to return all the POSITION nodes that contain CLIENTS whose
id is MDR.

But the only children of POSITION I want are the CLIENTS whose id is MDR.

If I do

/pallet/position/client[@id='MDR']/..

I get all the POSITIONS, but all CLIENTS in those positions, not just
CLIENTS whose id = 'MDR'

So, from my example XML, if I did an xpath to isolate @id='MBR', I would
like this to be my return list:

<pallet>
<position row="0" bay="0" level="A">
<client id="MDR">
<partnum id="A/P FILES " isStock="N">A/P FILES </partnum>
</client>
</position>
<position row="1" bay="1" level="B">
<client id="MDR">
<partnum id="A/P FILES " isStock="N">A/P FILES
</partnum>
</client>
</position>
<position row="1" bay="1" level="D">
<client id="MDR">
<partnum id="X-MAS DECORATION" isStock="N">X-MAS DECORATION
</partnum>
</client>
</pallet>

That's why I thought I'd use ancestor, to find all the clientnodes, and
then each client node's ancestor (which I think will exclude the other
child nodes of each position node).
May 25 '06 #3
It looks like you are wanting to use descendant:: rather than ancestor::

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
May 25 '06 #4


John Bailo wrote:

If I do

/pallet/position/client[@id='MDR']/..

I get all the POSITIONS, but all CLIENTS in those positions, not just
CLIENTS whose id = 'MDR'

So, from my example XML, if I did an xpath to isolate @id='MBR', I would
like this to be my return list:


XPath 1.0 selects existing nodes in the input document, it can't change
the structure of the original document. If you use
/pallet/position/client[@id='MDR']
you select the client elements with id attribute value 'MDR'.
If you want to filter out child nodes of the pallet root element but
still have that root around then you need an XSLT stylesheet to do that,
XPath alone does not help.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 25 '06 #5

Can the result of an XSLT transformation be a NodeList? Or XmlDocument?

Or is XSLT for display (*.html) purposes only?

Martin Honnen wrote:


John Bailo wrote:

If I do

/pallet/position/client[@id='MDR']/..

I get all the POSITIONS, but all CLIENTS in those positions, not just
CLIENTS whose id = 'MDR'

So, from my example XML, if I did an xpath to isolate @id='MBR', I
would like this to be my return list:

XPath 1.0 selects existing nodes in the input document, it can't change
the structure of the original document. If you use
/pallet/position/client[@id='MDR']
you select the client elements with id attribute value 'MDR'.
If you want to filter out child nodes of the pallet root element but
still have that root around then you need an XSLT stylesheet to do that,
XPath alone does not help.

May 25 '06 #6
John Bailo wrote:

Can the result of an XSLT transformation be a NodeList? Or XmlDocument?

Or is XSLT for display (*.html) purposes only?
Ok, looks like the answer is /yes/.

Here is some sample code I found that will output an XML text stream:

http://www.xmlforasp.net/CodeSection.aspx?csID=103

using System;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;

public class TransformXML
{
//This will transform xml document using xslt
//and produce result xml document
//and display it
public static void Main(string[] args)
{
//args[0]--xmldocument; [1]--xsl;
try {
StringWriter sw = new StringWriter();
XPathDocument xmlDoc = new XPathDocument(args[0]);
//Create XslTransform and load stylesheet
XslTransform trans1 = new XslTransform();
//Create resolver and provide evidence
trans1.Load(args[1]);
//Transform XML
trans1.Transform(xmlDoc,null,sw, new XmlUrlResolver());
Debug.WriteLine("\n\n"+sw.ToString() +"\n\n");
}
catch (Exception e)
{ Console.WriteLine ("Exception: {0}", e.ToString()); }
}}


Martin Honnen wrote:


John Bailo wrote:

If I do

/pallet/position/client[@id='MDR']/..

I get all the POSITIONS, but all CLIENTS in those positions, not just
CLIENTS whose id = 'MDR'

So, from my example XML, if I did an xpath to isolate @id='MBR', I
would like this to be my return list:


XPath 1.0 selects existing nodes in the input document, it can't
change the structure of the original document. If you use
/pallet/position/client[@id='MDR']
you select the client elements with id attribute value 'MDR'.
If you want to filter out child nodes of the pallet root element but
still have that root around then you need an XSLT stylesheet to do
that, XPath alone does not help.

May 25 '06 #7


John Bailo wrote:

Can the result of an XSLT transformation be a NodeList? Or XmlDocument?


The result of an XSLT transformation is a tree which can then be
serialized as an XML document (xsl:output method="xml") or as an HTML
document (xsl:output method="html") or as a plain text document
(xsl:output method="text"). So you can transform XML to XML with XSLT,
for instance filter output nodes in the input XML.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 26 '06 #8
Martin Honnen wrote:
The result of an XSLT transformation is a tree which can then be
serialized as an XML document (xsl:output method="xml") or as an HTML
document (xsl:output method="html") or as a plain text document
(xsl:output method="text"). So you can transform XML to XML with XSLT,
for instance filter output nodes in the input XML.

Excellent.

I've been playing around with it in my c# code and you're right, it
should do what I want.

I just hope there's a programmatic way of creating the XSLT document
because my queries will be changing from run to run.

So, I guess it breaks down to

XPath is the equivalent of a SELECT statement (returns the nodes)
XSLT is the equivalent of a WHERE clause (filters the results)
May 26 '06 #9


John Bailo wrote:
So, I guess it breaks down to

XPath is the equivalent of a SELECT statement (returns the nodes)
XSLT is the equivalent of a WHERE clause (filters the results)


Certainly not as far as XSLT goes, it is much more than an WHERE clause,
XSLT is able to construct new nodes/documents and can completely change
the structure and contents of the input XML.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 26 '06 #10
Martin Honnen wrote:


John Bailo wrote:
So, I guess it breaks down to

XPath is the equivalent of a SELECT statement (returns the nodes)
XSLT is the equivalent of a WHERE clause (filters the results)

Certainly not as far as XSLT goes, it is much more than an WHERE clause,
XSLT is able to construct new nodes/documents and can completely change
the structure and contents of the input XML.


Well that seems to be what I need, since you've established that XPath
can't return only certain child nodes and their antecedents w/out
returning all other antecedents of their parents.

May 26 '06 #11
John Bailo wrote:
Martin Honnen wrote: Well that seems to be what I need, since you've established that XPath
can't return only certain child nodes and their antecedents w/out
returning all other antecedents of their parents.


Ooops.

Make that "all other descendants of their parents".

May 26 '06 #12

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

Similar topics

3
by: Mike Partridge | last post by:
Is it possible to access your caller's (not parent) context while inside a <xsl:template match...> or <xsl:for-each...>? Here is the xml I'm using: <report-set> ...<report> .....<detail-data>...
1
by: Colin Fox | last post by:
Hi, all. Within an xsl template, you can use the <xsl:attribute> tag to set an attribute of the current output node. This is great. However, I need to be able to set an attribute of an...
2
by: Jesper | last post by:
Hi, Is it possible to query an object for an ancestor. I.e. determine if an object is derived from a certain type of class. thanx. Jespr.
3
by: Jack Addington | last post by:
Is there a quick and easy way in Visual Studio 2003 to get the method declaration from the ancestor so I can override/extend it? I know that if I am in another method or the constructor and type...
2
by: werD | last post by:
Hello, Im wondering about using xml to store relational data. It works well with .net but im having some trouble with the xsl/xpath. Lets say that I have an xml like <data> <files> <file...
3
by: Luis P. Mendes | last post by:
Hi, I have the following problem: I instantiate class Sistema from another class. The result is the same if I import it to interactive shell. s = Sistema("par") class Sistema:
3
by: Valvalis | last post by:
Hello, I am trying to set a class attribute of a text.item element to the value of its nearest ancestor. I want to do this in the case that the class of the text.item is currently a blank string....
4
by: Muthu08 | last post by:
I'm trying to Xpath EXprn for a current node(name unknown).I tried using the below syntax,but it fails .Pls help. <xsl:variable name= "xpath" select ="name(ancestor-or-self::(.))"/>
7
by: Ebenezer | last post by:
Hello! Let's suppose we have an XML with some nested NODE nodes: <root attr="first"> <node id="1" attr="mike"> <node id="2" /> <node id="3" attr="dave" /> </node> <node id="4">
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
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: 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...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.