473,385 Members | 2,044 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,385 software developers and data experts.

select nodes where a grandchild's text is not some value?

I have some XML that I want to transform to some XML:
Expand|Select|Wrap|Line Numbers
  1. <element>
  2.     <child>
  3.         <grandchild>
  4.             otherWord
  5.         </grandchild>
  6.         <grandchild>
  7.             triggerExclusion
  8.         </grandchild>
  9.     </child>
  10. </element>
  11. <element>
  12.     <child>
  13.         <grandchild>
  14.             otherWord
  15.         </grandchild>
  16.     </child>
  17. </element>
  18.  
I want to copy elements where 'triggerExclusion' is not the text of its grandchild subelement. In this example I want to copy the second element, not the first.

This doesn't work for me:
Expand|Select|Wrap|Line Numbers
  1. <template match="element[not(child/grandchild eq 'triggerExclusion')"]>
  2.     <copy>
  3.         <apply-templates/>
  4.     </copy>
  5. </template>
  6.  
My Saxon warns that a sequence can't be the first argument of the eq operator, and, I guess, only looks at the first grandchild.

Please, how do I select elements where a descendent of arbitrary depth has some value?

TIA
Sep 22 '08 #1
5 3748
MarkoKlacar
296 Expert 100+
Hi,

What you could do is select every child-element that doesn't contain a grandchild with the text "triggerExclusion".

It could look something like this:
(don't quite remember the syntax, but isn't text() a function that returns the value of an element?? In this case it could be "triggerExclusion"...anyway)

[HTML]//child/grandchild/text() != "triggerExclusion"[/HTML]

That should at least get you started if you haven't solved it already.

/MK
Sep 22 '08 #2
thank you for the thought. This would select grandchild elements that don't have the trigger. What I want is to select elements such that the grandchild doesn't have the trigger.

Something like --
Expand|Select|Wrap|Line Numbers
  1. //element[some test on grandchild I can't figure]
  2.  
Sep 23 '08 #3
Dormilich
8,658 Expert Mod 8TB
thank you for the thought. This would select grandchild elements that don't have the trigger. What I want is to select elements such that the grandchild doesn't have the trigger.
Expand|Select|Wrap|Line Numbers
  1. element[child/grandchild/text() != 'triggerExclusion']
note: about the same as in your post...

regards
Sep 23 '08 #4
jkmyoung
2,057 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. element[child/grandchild/text() != 'triggerExclusion']
note: about the same as in your post...

regards
Wouldn't this select the first element since it has a child/grandchild node that isn't equal to triggerExclusion?

I would suggest just replacing the eq with a =.

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="element[not (child/grandchild = 'triggerExclusion')]">
  2. <xsl:copy-of select="."/>
  3. </xsl:template>
  4. <xsl:template match="element"/>
  5.  
Sep 23 '08 #5
Dormilich
8,658 Expert Mod 8TB
Wouldn't this select the first element since it has a child/grandchild node that isn't equal to triggerExclusion?
I don't think so. It will select all <element> elements, that have not even one <grandchild> element with "triggerException". In this case, it should select the second one. note that the expression child/grandchild/text() is actually a node-set*, since there are two <grandchild> elements.

Or to ask it the other way round: what's the difference between element[child/grandchild/text() != 'triggerExclusion']** and element[not(child/grandchild/text() = 'triggerExclusion')] ? to me it is the same.

in this case (string) grandchild/text() and (string) grandchild gives the same, because there are no further child elements with text nodes (see specs @ w3c)

* you can test it with count(child/grandchild/text()), though I'm quite positive that the result will be 2
** expanded XPath is child::element[child::child/child::grandchild/child::text()]
Sep 23 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael Reiche | last post by:
Question on XSL expression Got this XML: <Body> <Page> <Line no="9" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line>
2
by: Cali | last post by:
Please bear with me, I have been reading about XSL for a couple hours. I have an XML document that contains multiple <page> tags interspersed throughout the tree. <text> .... <page>1</page>...
4
by: Larry R | last post by:
I am trying to use XPath (XSLT 1.0), EXSLT 1.1 (.Net) to select the nodelist consisting of the 'top n' nodes. THe counter is the count of item/value. Using a traditional for-each logic, the...
2
by: robin_hoods | last post by:
I'm having the following problem I want to create a XML document like <?xml version="1.0" encoding="utf-8"?> <RedlineXML xmlns="urn:autodesk.com:dsd:RedlineXML_v_002.xdr"...
2
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this...
13
by: André Nogueira | last post by:
Hi there. I know you can view a node's fullpath property, but is it posible to select a node using its path? Like, tell the treeview that the node that should be selected is the node with the...
3
by: astro | last post by:
I have a datagrid that is two levels down from the dataview (i.e. grandchild). I have spent 3 hours trying to get the syntax of determining it's real datasource (i.e. not it's source based on it's...
4
by: praveen | last post by:
I have a form with treeview control loaded from xml document,text box, two buttons named "Find" and "FindNext" and my treeview which looks like below. Details |__ policy status |__ created by...
3
by: thrill5 | last post by:
I have an xml document such as: <device> <element>first</element> <element>second</element> </device> I am using this as the source for an xslt transform that goes like <xsl:for-each...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.