473,769 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPath or XSL Transform Help

I am new to XML Programming and I am hoping someone can help me out
with this.

Assuming I have the following XML:

<root>
<E C="P_E1" O="E1" Y='True'>
<A C="P_E1A1" V="7" Y='True'/>
<A C="P_E1A2" V="8" />
</E>
<E C="P_E2" O="E1">
<A C="P_E1A1" V="7" />
<A C="P_E1A2" V="8" />
</E>
<E C="P_E3" O="3" Y='True'>
<A C="P_E3A1" V="15" Y='True'/>
<E C="P_E3E1" O="E1" Y='True'>
<A C="P_E3E1A1" V="15" Y='True'/>
<A C="P_E3E1A2" V="16" />
<A C="P_E3E1A3" V="17" />
<A C="P_E3E1A4" V="18" />
<E C="P_E3E1E1" O="E1" Y='True'>
<A C="P_E3E1E1A1 " V="15" Y='True'/>
</E>
</E>
</E>
<E C="P_E4" O="4" >
<A C="P_E4A1" V="19" />
<A C="P_E4A2" V="20" />
<E C="P_E4E1" O="E1" Y='True'>
<A C="P_E4E1A1" V="15" Y='True'/>
</E>
</E>
</root>

Basically, I want an xPath that will select all of the top most E
elements where Y='True'.
When I write top most, I mean only the followng:
- the parent, not children
- single node, if there are no children

So, for the example above, the following nodes would be selected:
- <E C="P_E1" O="E1" Y='True'>
- <E C="P_E3" O="3" Y='True'>
- <E C="P_E4E1" O="E1" Y='True'>

I assume this can be done; I just cannot get the syntax down.

Here is what I have so far: //E [@Y='True']. However, this selects all
of the nodes including the children.

If this helps, the Y attribute will either be equal to True on not
exist. As shown in the example above.

After those nodes are selected, I need to transform the nodes using
XSLT. I am mentioning this just in case the xPath cannot be written
and XSLT needs to be used to select the nodes. Once the nodes are
selected, I think I can take it from there.

Thanks for your help.

Regards,

R

Dec 11 '06 #1
2 1393
Candle wrote:
Basically, I want an xPath that will select all of the top most E
elements where Y='True'.
Your only difficulty here is making "top most" something that's
sufficiently explicit that you can express it in XSLT.

One way to say this: You want all E elements whose Y attribute is
"True", but whose parent's Y attribute is either absent or not "True".

//E[@Y="True" and not(../@Y="True")]

It's probably more efficient to rephrase this as: You want all E
elements whose Y attribute is "True", that are children of an element
whose Y attribute is either absent or not "True".

//*[not(@Y="True")]/E[@Y="True"]

If you know the parent is always going to be an E, it's probably even
more efficient to say:

//E[not(@Y="True")]/E[@Y="True"]

This is assuming that once Y becomes True, it is True for all descendant
E's below that point ... otherwise, this simple parent/child test
applied to all available E's won't work, and you'll need a more explicit
description of what "top most" means.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Dec 11 '06 #2
Joseph,

Worked like a charm.

Thx,

R

Joseph Kesselman wrote:
Candle wrote:
Basically, I want an xPath that will select all of the top most E
elements where Y='True'.

Your only difficulty here is making "top most" something that's
sufficiently explicit that you can express it in XSLT.

One way to say this: You want all E elements whose Y attribute is
"True", but whose parent's Y attribute is either absent or not "True".

//E[@Y="True" and not(../@Y="True")]

It's probably more efficient to rephrase this as: You want all E
elements whose Y attribute is "True", that are children of an element
whose Y attribute is either absent or not "True".

//*[not(@Y="True")]/E[@Y="True"]

If you know the parent is always going to be an E, it's probably even
more efficient to say:

//E[not(@Y="True")]/E[@Y="True"]

This is assuming that once Y becomes True, it is True for all descendant
E's below that point ... otherwise, this simple parent/child test
applied to all available E's won't work, and you'll need a more explicit
description of what "top most" means.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Dec 12 '06 #3

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

Similar topics

0
1635
by: K.Strunk | last post by:
Hi! I have a problem signing a XML-document. I need to sign a subnode of a document. So I need to refer to this subnode from within my signature. But how can I do that with XPath? I tried the following, but I couldn't verify it using an online-verifier (http://www.aleksey.com/xmlsec/xmldsig-verifier.html). Could anybody please help me with that reference? Thanx a lot!
6
2931
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 this, and came across a problem that I haven't been able to solve elegantly. The problem is to find "linker" vertexes that a pair of verteces from a pre-defined set. For example, if the graph verteces represent cities and edges represent flights...
3
3045
by: Tjerk Wolterink | last post by:
Hello i have xml code like this: <page:page xmlns:page="namespacefor page"> <page:section> <page:header> <b>Hello</b>There </page:header> <page:content> --- HTML CODE like: <i>Y</i>es i like bla bal <center>bla</center><img> alblalba
4
3450
by: Pat Turner | last post by:
Hi, I have some XML like this: <family> <person name="bob"> <father ref="../../person" /> </person> <person name="charlie"> <child ref="../../person" />
4
21210
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 native English speaker, it's quite hard to make the problem clear. Please see the following example.
1
1483
by: Sonu Kapoor | last post by:
Hi, I would like to use xpath with xslt. I know that this should be possible, but I dont get it ! Here is what I have tried so far: ==================================== my xml file: ====================================
2
1645
by: Pawel | last post by:
I have small problem with XslTransformation. I get from WebService xml document. I have xslt and I want transform xml document to html code. It's look easy but I cant't manage with xPath. Maybe someone help me with that. I have problems with xPath in xslt file. I can't navigate by names only by vertical and horizontal axis. What's wrong .... --- Code --- // WebService XmlForAnalysis.Xmla xa = new XmlForAnalysis.Xmla(); xa.Url =...
2
3567
by: Chucker | last post by:
Hi folks, I would like to select some nodes from a very large XML document and then apply a stylesheet to the dom fragment / nodelist that is the result of my XPath-Query. I used to use MSXML where I know how to do this. In .NET I am starting to get crazy because I don´t manage to transform my nodelist into an XPath-Navigable-Document. Can Anybody please help me?
2
1792
by: Monty | last post by:
Despite reading posts in Google, I don't understand XPATH. Can someone help me write an XPATH. From Google I think my problem is that the default namespace does not have a prefix. I can't change this as I have received this XML and I didn't create it. All I want to is retrieve the PROJECTNAME from the following XML. I am typing this XML and XPATH into this site http://www.activsoftware.com/xml/xpath/ The XPATH that does not work is...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9857
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7404
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.