mule xpath extractvalue mysql - mysql

I have a question about extracting a value with xpath
Some part of the xml:
<mark:info>
<mark:Information name="Adress" answer="SomeStreet"/>
<mark:Information name="PhoneNumber" answer="123456789"/>
</mark:info>
I want to receive the text "SomeStreet" with extractValue function in mysql
I was trying to create an xpath expression like
//mark:info/mark:Information[#name='Adress']
but I'm receiving the whole node. I need just the text "SomeStreet" but I'm not sure how to do it.

The xpath //mark:Information[#name="Adress"]/#answer should give SomeStreet
BTW shouldn't your xml have a xmlns specifying what is mark like :
<mark:info xmlns:mark="http://example.com"> ?

Related

Extracting json fields using XSLT

I am new to XSLT, currently I have a json string and I need to derive particular field from the json string . I am currently using fn:parse-json with map:get but the resultant seems to be empty .
Below is the sample snippet:
<xsl:variable name="json-temp" select="fn:parse-json($json-str)" />
<xsl:variable name="result" select="map:get($json-temp,2)" />
When I try to print result (Or) json-temp both seems to be empty - Can someone please help here. and let me know if I am missing anything.
json-str variable has the following value:
{
"testName":"pppp",
"testID":"1234p",
"testDept":"Dept"
}
You should be able to use map:get($json-temp, 'testID') (in XPath 3) or $json-temp?testID in XPath 3.1. I am not sure which value you want to extract with map:get($json-temp,2) as the map has no key of the value 2, that call would only make sense for e.g. map { 2: 'foo' } to extract e.g. foo.
The best way to use JSON in DataPower is by using GatewayScript instead of XSLT. If you really need to stick to XSLT, you can try using:
<xsl:variable name="jsonx" select="dp:stringToJSONx($json-str)"/>
From there, you can extract the field you want by using XPath on the resulting JSONx document.

How to write an XPath query for text within <script> using PhantomJS

I am trying to scrape some specific content that sits within the <script> section of a page (at the bottom of the page before the end of the tag. It is my understanding that this can't be done with regular XPath, so I will be using PhantomJs cloud via SEOTools for Excel plugin.
Please see code below:
<script> window.__INITIAL_STATE__ = {"questions":{"list":{},"status":{}},"sites":{"list":{"SEOTest":{"joined":"2016-04-17T22:00:31.000Z","threshold":[],"abn":"8724483318952",
I want to be able to scrape the text after "ABN" field, so the xpath would return "8724483318952". Does anybody know how this can be done with xpath?
To retrieve the desired target string value of "8724483318952" you can use the following XPath-1.0 expression:
substring-before(substring-after(script,'abn":'),',')
It gets the desired string from the <script> tag and its output is
"8724483318952"
The signature of XPathUrl is, according to this link:
=XPathOnUrl(
string url,
string xpath,
string attribute,
string xmlHttpSettings,
string mode
) : vector
So the whole expression could look like this:
=XPathOnUrl(A2,"substring-before(substring-after(//ul[#class='headshot']/script,'abn":'),',')")
I'm not sure that this expression really does work, but it should give you a pretty precise idea of how to handle XPath expression generally.

How to access various parts of a link with XPath

I'm fairly new to XPath and wanted to see how granular you can get when accessing various HTML components.
I'm currently using the this xpath
//*[#id=\"resultsDiv\"]/p[1]/a
to access the HTML (abbreviated) below:
<p style="margin:0;border-width:0px;">Bill%20Jones</p>
The XPath returns this: Bill%20Jones
But what I'm trying to get is simply the PersonID = 140476.
Question: Is it possible to write an XPath that results in 140476, or do I need to take what was returned and use a regular expression other method to access the PersonID.
If this XPath,
//*[#id=\"resultsDiv\"]/p[1]/a
selects this a element,
Bill%20Jones
then this XPath,
substring-after(//*[#id='resultsDiv']/p[1]/a/#href, 'PersonID=')
will return 140476 alone, as requested.

XPath to extract a portion of attribute

I'm new to Xpath and I'm trying to figure out how to extract the attribute of the extension with the value of D000001602 as shown below.
<ClinDoc>
<ComponentOf>
<encompassingEncounter>
<id root="2.16.840.1.113883.3.52.3" extension="D000001602"/>
<effectiveTime>
<low value="20140620135800"/>
<high value="20140701140756"/>
</effectiveTime>
</encompassingEncounter>
</componentOf>
</ClinDoc>
I am using an online extractor with the following code but I can't seem to get it to work:
/clindoc/componentof/encompassingEncounter/id[#root=2.16.840.1.113883.3.529.3]/#extension
//id[#root=2.16.840.1.113883.3.529.3]/#extension
Thanks much!
You're trying to match root with the string value 2.16.840.1.113883.3.52.3, which means you need to represent it as a string literal in the XPath.
Also, node names are case sensitive:
/ClinDoc/Componentof/encompassingEncounter/id[#root="2.16.840.1.113883.3.529.3"]/#extension

XPATH matches function problem-- works but doesn't work

I'm using Eclipse to run an XSL 2.0 (XPATH 2.0), and I have the following source:
<testTop>
<Level1 id="abc" Text="from 1-2"/>
<Level1 id="pqr" Text="from 3-44" />
<Level1 id="xyz" Text="from 49-101" />
</testTop>
When I test the following expression in Eclipse, //*[matches(#Text, '\d+-\d+')] I get the right nodes, but not the Text attributes themselves
Level1 ID=abc
Level1 ID=pqr
Level1 ID=xyz
... whereas //#Text gives me the Text attributes. Can anyone help me to understand why?? I'd like to get the Text attribute values and parse them using string functions. THE END RESULT SHOULD LOOK LIKE THIS:
<output originalText="from 1-2" value1="1" value2="2" />
Shouldn't I be getting all the attributes that are part of each node that matched?
Your XPath is selecting the elements that have the attributes you want. If you want to select the #Text that match your pattern, you need to adjust your XPath to select the attributes rather than the element.
You could use this XPath:
//*[matches(#Text, '\d+-\d+')]/#Text
or this XPath:
//*/#Text[matches(., '\d+-\d+')]