Can this XPath expression be minified - xpath

I'm not an XPath expert and I couldn't find a tool to do this. Is there a way to minify this XPath statement? 80% is redundant.
XPATH 2
(//CustomField | //fields)[
(fullName/text[not(matches(#Image, "chk_[a-zA-Z0-9]+__c"))] and type/text[#Image="Checkbox"]) or
(fullName/text[not(matches(#Image, "txt_[a-zA-Z0-9]+__c"))] and type/text[#Image="Text"]) or
(fullName/text[not(matches(#Image, "txa_[a-zA-Z0-9]+__c"))] and type/text[#Image="Textarea"]) or
(fullName/text[not(matches(#Image, "txr_[a-zA-Z0-9]+__c"))] and type/text[#Image="Richtext"]) or
(fullName/text[not(matches(#Image, "txl_[a-zA-Z0-9]+__c"))] and type/text[#Image="LongTextArea"]) or
(fullName/text[not(matches(#Image, "num_[a-zA-Z0-9]+__c"))] and type/text[#Image="Number"]) or
(fullName/text[not(matches(#Image, "dat_[a-zA-Z0-9]+__c"))] and type/text[#Image="Date"]) or
(fullName/text[not(matches(#Image, "lkp_[a-zA-Z0-9]+__c"))] and type/text[#Image="Lookup"]) or
(fullName/text[not(matches(#Image, "mdr_[a-zA-Z0-9]+__c"))] and type/text[#Image="MasterDetail"]) or
(fullName/text[not(matches(#Image, "dtm_[a-zA-Z0-9]+__c"))] and type/text[#Image="DateTime"]) or
(fullName/text[not(matches(#Image, "url_[a-zA-Z0-9]+__c"))] and type/text[#Image="Url"]) or
(fullName/text[not(matches(#Image, "pkl_[a-zA-Z0-9]+__c"))] and type/text[#Image="Picklist"]) or
(fullName/text[not(matches(#Image, "pkm_[a-zA-Z0-9]+__c"))] and type/text[#Image="MultiselectPicklist"]) or
(fullName/text[not(matches(#Image, "cur_[a-zA-Z0-9]+__c"))] and type/text[#Image="Currency"]) or
(fullName/text[not(matches(#Image, "pct_[a-zA-Z0-9]+__c"))] and type/text[#Image="Percent"]) or
(fullName/text[not(matches(#Image, "fcur_[a-zA-Z0-9]+__c"))] and type/text[#Image="Currency"] and formula) or
(fullName/text[not(matches(#Image, "rcnt_[a-zA-Z0-9]+__c"))] and type/text[#Image="Summary"] and summaryOperation/text[#Image="count"])
]
This is a stripped down version of an XML document with one match
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<fields>
<fullName>txl_Description__c</fullName>
<deprecated>false</deprecated>
<externalId>false</externalId>
<label>Price Schedule Description</label>
<length>4000</length>
<trackHistory>false</trackHistory>
<trackTrending>false</trackTrending>
<type>LongTextArea</type>
<visibleLines>5</visibleLines>
</fields>
<fields>
<fullName>Reason_For_Override__c</fullName>
<deprecated>false</deprecated>
<externalId>false</externalId>
<label>Reason for Override</label>
<length>1000</length>
<trackHistory>false</trackHistory>
<trackTrending>false</trackTrending>
<type>LongTextArea</type>
<visibleLines>2</visibleLines>
</fields>
</CustomObject>

You can replace all those occurrences of text() with ., which is better practice anyhow.
You could pass in a parameter $data containing a lookup table: <data><key a="chk" b="Checkbox"/><key a="..." b="..."/>...</data> and then do
some $key in $data/data/key
satisfies fullName[not(matches(., concat($key/#a, "_[a-zA-Z0-9]+__c"))]
and type[.=$key/#b])

I thoroughly checked your expression and it looks like that there is near zero redundancy. The part _[a-zA-Z0-9]+__c is of low relevance in optimizing the expression.
Creating tuples like ("chk","Checkbox") and ("txt","TextBox") will neither improve readability nor performance, even if it seems like that. So you're good to go, AFAIK.

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:

how to read the data from XML with spaces using oracle

I want to read the data from passage_para tag, after passage_para I have 2 spaces before the expression tag and after the expression tag I have one more space, etc. When I use extract function to get the passage_para tag from the XMLTYPE column it is eliminating all the spaces.
<?xml version="1.0" encoding="UTF-8"?> <item> <information number="sdjsadh" > <response_direction delivery_mode="xcs"> <dparagraph>test</dparagraph> </response_direction> </information> <i_content> <stimulus_reference> <passage> <prose style="1"> <passage_para> <expression> <math xmlns="Math" xmlns:xlink="xlink" display="inline" overflow="scroll"> <mr> <mi>z</mi> <mo>></mo> <mn>0</mn> </mr> </math> </expression> </passage_para> </prose> </passage> </stimulus_reference> </i_content> </item>
which I don't want because it is taking out the spaces. The desired output I need is " z > 0 ".
Note: Between the passage_para tag the child nodes may change, they are not going to be the same.

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

trying to parse specific data using xpath

I have a small xml file that I'm trying to grab the away_team first and then the home_team second.
/game/team/statistics/#goals gives me the data I want but I need to reverse the order. So I'm trying to understand how to get the away_team goals first, followed by the home_team.
Below is the file
<game id="f24275a9-4f30-4a81-abdf-d16a9aeda087" status="closed" coverage="full" home_team="4416d559-0f24-11e2-8525-18a905767e44" away_team="44167db4-0f24-11e2-8525-18a905767e44" scheduled="2013-10-10T23:00:00+00:00" attendance="18210" start_time="2013-10-10T23:08:00+00:00" end_time="2013-10-11T01:32:00+00:00" clock="00:00" period="3" xmlns="http://feed.elasticstats.com/schema/hockey/game-v2.0.xsd">
<venue id="bd7b42fa-19bb-4b91-8615-214ccc3ff987" name="First Niagara Center" capacity="18690" address="One Seymour H. Knox III Plaza" city="Buffalo" state="NY" zip="14203" country="USA"/>
<team name="Sabres" market="Buffalo" id="4416d559-0f24-11e2-8525-18a905767e44" points="1">
<scoring>
<period number="1" sequence="1" points="1"/>
<period number="2" sequence="2" points="0"/>
<period number="3" sequence="3" points="0"/>
</scoring>
<statistics goals="1" assists="2" penalties="7" penalty_minutes="23" team_penalties="0" team_penalty_minutes="0" shots="27" blocked_att="14" missed_shots="8" hits="25" giveaways="5" takeaways="10" blocked_shots="7" faceoffs_won="22" faceoffs_lost="28" powerplays="1" faceoffs="50" faceoff_win_pct="44.0" shooting_pct="3.7" points="3">
<powerplay faceoffs_won="2" faceoffs_lost="0" shots="0" goals="0" missed_shots="1" assists="0" faceoff_win_pct="100.0" faceoffs="2"/>
<shorthanded faceoffs_won="3" faceoffs_lost="3" shots="1" goals="0" missed_shots="0" assists="0" faceoffs="6" faceoff_win_pct="50.0"/>
<evenstrength faceoff_win_pct="40.5" missed_shots="7" goals="1" faceoffs_won="17" shots="26" faceoffs="42" faceoffs_lost="25" assists="2"/>
<penalty shots="0" goals="0" missed_shots="0"/>
</statistics>
<shootout shots="0" missed_shots="0" goals="0" shots_against="0" goals_against="0" saves="0" saves_pct="0"/>
<goaltending shots_against="33" goals_against="4" saves="29" saves_pct="0.879" total_shots_against="33" total_goals_against="4">
<powerplay shots_against="0" goals_against="0" saves="0" saves_pct="0"/>
<shorthanded shots_against="7" goals_against="0" saves="7" saves_pct="1.0"/>
<evenstrength goals_against="4" saves_pct="0.846" shots_against="26" saves="22"/>
<penalty shots_against="0" goals_against="0" saves="0" saves_pct="0"/>
<emptynet goals_against="0" shots_against="0">
<powerplay goals_against="0"/>
<shorthanded goals_against="0"/>
<evenstrength goals_against="0"/>
</emptynet>
</goaltending>
Here's an XPath 2.0 expression that should do what you asked, yielding a sequence of two elements:
(/game/team[#id = /game/#home_team]/statistics/#goals,
/game/team[#id = /game/#away_team]/statistics/#goals)
Credit to #Ian for sleuthing out the details of the question.
In XPath 1.0, you could concatenate string data from the two teams in whatever order you want:
concat(/game/team[#id = /game/#home_team]/statistics/#goals, ' ',
/game/team[#id = /game/#away_team]/statistics/#goals)
But as Ian said, you can't produce a nodeset with an order different from document order. (I don't think a nodeset has any intrinsic order at all... it's how it's processed that imposes an order.)
Update:
As Ian pointed out, your XML data is in a namespace, thanks to the default namespace declaration on <game>. Since you said that "/game/team/statistics/#goals gives me the data", I'm assuming that you've already taken care of this aspect of the problem, perhaps by declaring the default namespace in your XPath execution environment.

XPath for overview values of emma report

I generate EMMA reports during my build, they look like this
<report>
<stats>
<packages value="110"/>
<classes value="1762"/>
<methods value="12617"/>
<srcfiles value="962"/>
<srclines value="61320"/>
</stats>
<data>
<all name="all classes">
<coverage type="class, %" value="2% (42/1762)"/>
<coverage type="method, %" value="2% (302/12617)"/>
<coverage type="block, %" value="3% (6849/258033)"/>
<coverage type="line, %" value="3% (1592.9/61320)"/>
I need to get the percentage from the value attributes of the /report/data/all/coverage nodes. Currently getting these:
Invalid XPath expression: "/report/data/all/coverage[starts-with(#type,'block')]#value": Unexpected '#'
Invalid XPath expression: "substring-before(/report/data/all/coverage[starts-with(#type,'block']#value,'%')": Expected: )
You are missing a forward slash from the XPath before the #value attribute. There is also a missing brackets in your starts-with function
Try the following
/report/data/all/coverage[starts-with(#type,'block')]/#value
substring-before(/report/data/all/coverage[starts-with(#type,'block')]/#value,'%')

Resources