XPath to identify a parent based on two related children - xpath

Using the following Example, I am trying to create an XPath that will identify the id of Apples where their branchID matches the ID of a branch, but the treeID doesn't match the branch's treeID.
for instance: //growth[#type="apple"][branchID=//branch/#id]/#id - results would be
Granny
Empire
Gala
And //growth[#type="apple"][treeID!=//branch/treeID]/#id - results would be
Granny
Empire
Gala
But I want a query that will only return:
Granny
<xml>
<growth type="apple" id="Granny">
<branchID>ABCD</branchID>
<treeID>456</treeID>
</growth>
<growth type="apple" id="Empire">
<branchID>ABCD</branchID>
<treeID>123</treeID>
</growth>
<growth type="apple" id="Gala">
<branchID>EFGH</branchID>
<treeID>456</treeID>
</growth>
<growth type="flower" id="white">
<branchID>EFGH</branchID>
<treeID>123</treeID>
</growth>
<growth type="flower" id="yellow">
<branchID>ABCD</branchID>
<treeID>456</treeID>
</growth>
<branch id="ABCD">
<treeID>123</treeID>
</branch>
<branch id="EFGH">
<treeID>456</treeID>
</branch>
<tree id="123" />
<tree id="456" />
<tree id="789" />
</xml>

So the required item(s) (where the branchID/treeID pair does not exist in a branch element) will have different index values for the branchID in the list of all //branch/#id values and the treeID in the list of all //branch/treeID values...
//growth[#type="apple"][index-of(//branch/#id,branchID)!=index-of(//branch/treeID,treeID)]/#id
Granny
Nice question to give the little grey cells some exercise on a Friday lunchtime :o)

Related

How to specify symbol/character in os-signpost-point-schema

I have a custom Xcode 13.2.1 (13C100) Instrument to which I have recently added os-signpost-point-schema. I notice that the events are marked with a hyphen/dash rather than a ⓢ. See the comparison of my custom tool vs the standard “Points of Interest” tool:
I have been digging through the documentation and while I wager that there is some simple attribute that can be set to dictate which symbol is included within the signpost ⃝, it is not jumping out at me. How does one select the symbol used within custom event points in Instruments?
Here is the code for the instrument:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Instruments Developer Help: https://help.apple.com/instruments/developer/mac/current/ -->
<package>
<id>com.robertmryan.CustomInterval</id>
<version>0.2</version>
<title>Custom Points of Interest</title>
<owner>
<name>Robert Ryan</name>
</owner>
<import-schema>os-signpost</import-schema>
<!-- See https://help.apple.com/instruments/developer/mac/current/#/dev536412616 -->
<os-signpost-point-schema>
<id>custom-point-schema</id>
<title>Points</title>
<owner>
<name>Robert Ryan</name>
</owner>
<purpose>Provide mechanism for multicolored events posted by `os_signpost`; The string generated by `os_signpost` must be in form of "Label:%d,Concept:%{public}#", where "Label" is string that will control what text appears in the event, and "Concept" is one of the strings listed in https://help.apple.com/instruments/developer/mac/current/#/dev66257045 that dictates the color of the interval. No spaces after the commas within this string.</purpose>
<note>That message must use that printf-style format, not embedding the values in the format string literal.</note>
<!-- you can constrain this to a particular subsystem if you'd like:
<subsystem>"com.domain.MyApp"</subsystem>
-->
<category>"Interval"</category>
<name>?name</name>
<pattern>
<message>"Label:" ?label ",Concept:" ?concept</message>
</pattern>
<column>
<mnemonic>name</mnemonic>
<title>Name</title>
<type>string</type>
<expression>?name</expression>
</column>
<column>
<mnemonic>label</mnemonic>
<title>Label</title>
<type>string</type>
<expression>?label</expression>
</column>
<column>
<mnemonic>concept</mnemonic>
<title>Concept</title>
<type>event-concept</type>
<expression>?concept</expression>
</column>
</os-signpost-point-schema>
<os-signpost-interval-schema>
<id>custom-interval-schema</id>
<title>Intervals</title>
<owner>
<name>Robert Ryan</name>
</owner>
<purpose>Provide mechanism for multicolored intervals posted by `os_signpost`; The string generated by `os_signpost` must be in form of "Label:%d,Concept:%{public}#", where "Label" is string that will control what text appears in the interval, and "Concept" is one of the strings listed in https://help.apple.com/instruments/developer/mac/current/#/dev66257045 that dictates the color of the interval. No spaces after the commas within this string.</purpose>
<note>That message must use that printf-style format, not embedding the values in the format string literal.</note>
<!-- you can constrain this to a particular subsystem if you'd like:
<subsystem>"com.domain.MyApp"</subsystem>
-->
<category>"Interval"</category>
<name>?name</name>
<start-pattern>
<message>"Label:" ?label ",Concept:" ?concept</message>
</start-pattern>
<column>
<mnemonic>name</mnemonic>
<title>Name</title>
<type>string</type>
<expression>?name</expression>
</column>
<column>
<mnemonic>label</mnemonic>
<title>Label</title>
<type>string</type>
<expression>?label</expression>
</column>
<column>
<mnemonic>concept</mnemonic>
<title>Concept</title>
<type>event-concept</type>
<expression>?concept</expression>
</column>
</os-signpost-interval-schema>
<instrument>
<id>com.robertmryan.CustomInterval.instrument</id>
<title>Custom Points of Interest</title>
<category>Behavior</category>
<purpose>Provide multi-colored intervals as dictated by the "event-concept" parsed from the `start-pattern` string.</purpose>
<icon>Generic</icon>
<limitations></limitations>
<create-table>
<id>custom-interval-table</id>
<schema-ref>custom-interval-schema</schema-ref>
</create-table>
<create-table>
<id>custom-point-table</id>
<schema-ref>custom-point-schema</schema-ref>
</create-table>
<graph>
<title>Custom Interval Graph</title>
<lane>
<title>Points</title>
<table-ref>custom-point-table</table-ref>
<plot-template>
<instance-by>name</instance-by>
<label-format>%s</label-format>
<value-from>name</value-from>
<color-from>concept</color-from>
<label-from>label</label-from>
</plot-template>
</lane>
<lane>
<title>Intervals</title>
<table-ref>custom-interval-table</table-ref>
<plot-template>
<instance-by>name</instance-by>
<label-format>%s</label-format>
<value-from>name</value-from>
<color-from>concept</color-from>
<label-from>label</label-from>
<qualified-by>layout-qualifier</qualified-by>
</plot-template>
</lane>
</graph>
<list>
<title>Custom Regions of Interest</title>
<table-ref>custom-interval-table</table-ref>
<column>name</column>
<column>label</column>
<column>concept</column>
<column>start</column>
<column>duration</column>
</list>
<list>
<title>Custom Points of Interest</title>
<table-ref>custom-point-table</table-ref>
<column>name</column>
<column>label</column>
<column>concept</column>
</list>
</instrument>
</package>
I posted this on the Apple forums, too, and received this answer:
… To customize the icon that is set in the point rendering scenario, your type that is selected in your value-from field needs to have a "Special Value Treatment" defined. In your case, instead of using name, you could safely use event-concept.
The mapping between Value -> (Icon, Color) can be found in the etype documentation. For event concept, that would be: https://help.apple.com/instruments/developer/mac/current/#/dev66257045
Please let me know if that helps!
Kacper
Posted 57 minutes ago by kacperh_ 
In short, the event-concept can control both the color and the symbol for the event, too.
So, I replaced the value-from in the points lane to use the parsed event-concept string, just like the color-from was doing:
<lane>
<title>Points</title>
<table-ref>custom-point-table</table-ref>
<plot-template>
<instance-by>name</instance-by>
<label-format>%s</label-format>
<value-from>concept</value-from>
<color-from>concept</color-from>
<label-from>label</label-from>
</plot-template>
</lane>
And that yielded:

Is possible to extract the text of an element compared with the end of the value of an attribute of current node?

I have an XML like this
<Values>
<Value ID="Contents01" Name="Contents 01" QualifierID="en-US">
<Text>It is a test [{placeHolder01}]</Text>
</Value>
<Value ID="VarPlaceHolderValue01" Name="Var Place Holder 01" QualifierID="en-US">[{placeHolder01}]</Value>
<Value ID="Contents02" Name="Contents 02" QualifierID="en-US">
<Text>Some extra text.</Text></Value>
<Value ID="PlaceHolder01" Name="PlaceHolder 01" QualifierID="en-US">
<Text>For StackOverflow</Text>
</Value>
</Values>
Would be possible to get with an expression the QualifierID of the PlaceHolderValue01, having the currently selected node the PlaceHolder01.
So the idea would be something like this from an already selected node.
//Values/Value[starts-with(#ID,'Var') and substring(./#ID, string-length(./#ID) - 2) = substring(#ID, string-length(#ID) - 2)]/text()
However I am getting syntax error with the xpath checkers, how it should work correctly?
Is it possible to do this with only xpath? The idea is to extract the text of the element VarPlaceHolderValue01, knowing that starts with Var and ends with the same number value of the current selected node?
Trying it out in iPython:
First, to select the node:
In [11]: root.xpath('//Value[starts-with(#ID, "PlaceHolder")]')
Out[11]: [<Element Value at 0x1094a1a00>]
Next, to isolate the string to be matched:
In [13]: root.xpath('substring-after(//Value[starts-with(#ID, "PlaceHolder")]/#ID, "PlaceHolder")')
Out[13]: '01'
Next, to match the "Var"-starting element and extract its text.
In [18]: root.xpath('string(//Value[starts-with(#ID, "Var") and contains(#ID, substring-after(//Value[starts-with(#ID, "PlaceHolder")]/#ID, "PlaceHolder"))])')
Out[18]: '[{placeHolder01}]'

add multiple columns with liquibase using yml

I want to add multiple columns to my database using liquibase and a yml-file.
I know that I can do this with one step using xml like this:
<changeSet author="liquibase-docs" id="addColumn-example">
<addColumn catalogName="cat"
schemaName="public"
tableName="person">
<column name="job" type="varchar(255)"/>
<column name="designation" type="varchar(255)"/>
</addColumn>
</changeSet>
Can I do the same in a yml-file?
- changeSet:
id: myId
author: malt
changes:
- addColumn:
tableName: myTable
columns:
- column:
name: name01
type: decimal(21,2)
- column:
name: name02
type: decimal(21,2)
This does not seem to work...
I just don't want to repeat the -addColumn-Tag again and again.
Thanks for your help!
Matthias
According to addColumn liquibase documentation you can do this in yaml as such (just their example):
databaseChangeLog:
- changeSet:
id: addColumn-example
author: liquibase-docs
changes:
- addColumn:
tableName: person
columns:
name: middlename
type: varchar(50)
You almost got it right, just need an extra indent after column:
- changeSet:
id: myId
author: malt
changes:
- addColumn:
tableName: myTable
columns:
- column:
 # note the indent below here!
name: name01
type: decimal(21,2)
- column:
name: name02
type: decimal(21,2)


Umbraco 7 xpath expression filter - i cant get it to load any nodes at all

I am new to xpath. I am trying to use the "nuPickers XML Dropdown picker" on Umbraco 7.3.4
but no matter what xpath xpression filter i use, the dropdown remains empty no nodes is being loaded in to the dropdown
i tried the following filters:
$root/
$site/
/*/
$ancestor-or-self::Home/
but to no avail, none of them loads any nodes
i actually want to select all the "Club" nodes under "Clubcontainer", but i cant get it to load any nodes, nevermind the specific ones that i actually want. My Umbraco.config looks as follows: (some nodes removed under to only show relevant nodes for my filter query.)
<root id="-1">
<Home id="2081" key="ebb9222f-f26c-4462-9f5d-43dba520326f" parentID="-1" level="1" creatorID="0" sortOrder="0" createDate="2015-12-29T12:19:53" updateDate="2016-01-09T17:27:57" nodeName="Home" urlName="home" path="-1,2081" isDoc="" nodeType="1070" creatorName="Gerrie Pretorius" writerName="Gerrie Pretorius" writerID="0" template="1049" nodeTypeAlias="Home">
<Clubcontainer id="2094" key="6f11e986-3e29-4555-8bc4-5a847600704c" parentID="2081" level="2" creatorID="0" sortOrder="3" createDate="2015-12-29T13:20:15" updateDate="2016-01-09T17:27:57" nodeName="Chess Clubs" urlName="chess-clubs" path="-1,2081,2094" isDoc="" nodeType="2092" creatorName="Gerrie Pretorius" writerName="Gerrie Pretorius" writerID="0" template="0" nodeTypeAlias="Clubcontainer">
<Club id="2103" key="856c9937-cf4c-481b-aaba-487e0dcee199" parentID="2094" level="3" creatorID="0" sortOrder="0" createDate="2016-01-07T22:41:28" updateDate="2016-01-09T17:27:57" nodeName="Hlalefang Alexandra Chess club" urlName="hlalefang-alexandra-chess-club" path="-1,2081,2094,2103" isDoc="" nodeType="2093" creatorName="Gerrie Pretorius" writerName="Gerrie Pretorius" writerID="0" template="0" nodeTypeAlias="Club">
<president><![CDATA[Mr President]]></president>
<presidentCell><![CDATA[0123 13131313]]></presidentCell>
<presidentEmail><![CDATA[johnDoe#example.net]]></presidentEmail>
</Club>
<Club id="2104" key="a5d73286-9572-445b-9d3a-7f758de64d0e" parentID="2094" level="3" creatorID="0" sortOrder="1" createDate="2016-01-07T22:42:27" updateDate="2016-01-09T17:27:57" nodeName="Chess Excellence" urlName="chess-excellence" path="-1,2081,2094,2104" isDoc="" nodeType="2093" creatorName="Gerrie Pretorius" writerName="Gerrie Pretorius" writerID="0" template="0" nodeTypeAlias="Club">
<president><![CDATA[Jane Doe]]></president>
<presidentCell><![CDATA[012 345 6789]]></presidentCell>
<webAddress><![CDATA[http://www.example.net]]></webAddress>
<presidentEmail><![CDATA[janedoe#example.net]]></presidentEmail>
</Club>
</Clubcontainer>
</Home>
</root>
If some-one can help me witht his i would greatly appreciate it.
Found the answer provided to me by Marc Goodson here
To load all Nodes of documentType Club use //Club
or to load the specific club nodes:
$ancestorOrSelf/ancestor-or-self::Home[position()=1]//Clubcontainer//Club

I have several XML documents that have different amount of names under images on each page

I have several XML documents that have different amount of names under images on each page. It can be one name or it could be 50. how can I insert this into a SQL database?
This is a snippet of the XML, so under images there is a name is this there are 2, but the next XML could have 10. the info inside of name is the same every time. How do I insert into SQL when these can be different any or every time?
-
-
1073073r1Prepress_step_CDI-SDDC_DRed_1.len
49.9429
21.7758
2400.0
1087.549
1
1
51.1929
23.0258
1178.76
"./images/7-17-14_Flat_1_FRC250Conv/1073073r1Prepress_step_CDI-SDDC_DRed_1__.len.gif"
-
1070635r0Prepress_step_CDI-SD_K_1.len
27.4746
6.7833
2400.0
186.369
1
1
29.6695
8.9782
266.379
"./images/7-17-14_Flat_1_FRC250Conv/1070635r0Prepress_step_CDI-SD_K_1__.len.gif"
-<Name>
1073073r1Prepress_step_CDI-SDDC_DRed_1.len
<Width unit="inch">49.9429</Width>
<Height unit="inch">21.7758</Height>
<Resolution unit="DPI">2400.0</Resolution>
<Area unit="sq in">1087.549</Area>
<X-Repeat>1</X-Repeat>
<Y-Repeat>1</Y-Repeat>
<Used_Width unit="inch">51.1929</Used_Width>
<Used_Height unit="inch">23.0258</Used_Height>
<TotalArea unit="sq in">1178.76</TotalArea>
<GIF-IMAGE> "./images/7-17-14_Flat_1_FRC250Conv/1073073r1Prepress_step_CDI- SDDC_DRed_1__.len.gif" </GIF-IMAGE>
</Name>
-<Name>
1070635r0Prepress_step_CDI-SD_K_1.len
<Width unit="inch">27.4746</Width>
<Height unit="inch">6.7833</Height>
<Resolution unit="DPI">2400.0</Resolution>
<Area unit="sq in">186.369</Area>
<X-Repeat>1</X-Repeat>
<Y-Repeat>1</Y-Repeat>
<Used_Width unit="inch">29.6695</Used_Width>
<Used_Height unit="inch">8.9782</Used_Height>
<TotalArea unit="sq in">266.379</TotalArea>
<GIF-IMAGE> "./images/7-17-14_Flat_1_FRC250Conv/1070635r0Prepress_step_CDI-SD_K_1__.len.gif" </GIF-IMAGE>
</Name>

Resources