I am trying to form an html template with xslt where I need to parse values from a variable containing xml string. But not being able to do so. If I try to print the variable it's showing the whole xml string with < and > being replaced with < and > respectively , but is not being parsed with xpath when tried.
Below is my xml string looks like which I stored in a variable named "SpecificOrderDetails". If I try the expression
<xsl:value-of select="$SpecificOrderDetails/SPECIFICORDERDETAILS/text()"/>
it gives me null value as output
<SPECIFICORDERDETAILS><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Hard-wired Return Path</COMPONENTNAME><COMPONENTID>101401</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Platinum Included FBO Movies</COMPONENTNAME><COMPONENTID>101500</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>iQ Discount</COMPONENTNAME><COMPONENTID>101501</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Primary Discounts</COMPONENTNAME><COMPONENTID>101504</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>03 Foxtel iQ</COMPONENTNAME><COMPONENTID>101601</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>TV - 24 Month Contract</COMPONENTNAME><COMPONENTID>101714</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Standard Install - No Offer</COMPONENTNAME><COMPONENTID>101723</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>My Platinum Eligibility</COMPONENTNAME><COMPONENTID>101900</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Commitment Eligibility</COMPONENTNAME><COMPONENTID>101913</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Platinum Channels</COMPONENTNAME><COMPONENTID>990015</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>4</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Smartcard</COMPONENTNAME><COMPONENTID>101</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>4</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>iQ PDR - Satellite</COMPONENTNAME><COMPONENTID>201</COMPONENTID></ORDERROW></SPECIFICORDERDETAILS>
If I try to print the variable it shows the whole xml string as below
<tr>
<td class="headingSubText" style="font-size:13pt; padding:10px 0px 0px 15px"><SPECIFICORDERDETAILS><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Hard-wired Return Path</COMPONENTNAME><COMPONENTID>101401</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Platinum
Included FBO Movies</COMPONENTNAME><COMPONENTID>101500</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>iQ
Discount</COMPONENTNAME><COMPONENTID>101501</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Primary
Discounts</COMPONENTNAME><COMPONENTID>101504</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>03
Foxtel iQ</COMPONENTNAME><COMPONENTID>101601</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>TV
- 24 Month Contract</COMPONENTNAME><COMPONENTID>101714</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Standard
Install - No Offer</COMPONENTNAME><COMPONENTID>101723</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>My
Platinum Eligibility</COMPONENTNAME><COMPONENTID>101900</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Commitment
Eligibility</COMPONENTNAME><COMPONENTID>101913</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>1</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Platinum
Channels</COMPONENTNAME><COMPONENTID>990015</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>4</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>Smartcard</COMPONENTNAME><COMPONENTID>101</COMPONENTID></ORDERROW><ORDERROW><CATEGORY>4</CATEGORY><ACTION>0</ACTION><COMPONENTNAME>iQ
PDR - Satellite</COMPONENTNAME><COMPONENTID>201</COMPONENTID></ORDERROW></SPECIFICORDERDETAILS>
</td>
</tr>
Please help someone on how to parse the variable inside xslt . Let know if I was not clear enough. This would my first question ever asked on stackoverflow.
Got it working !
Used xmlns:saxon="http://saxon.sf.net/" extension for xslt2.0 and it works perfectly to parse the xml string in the variable like below.
<xsl:value-of select="saxon:parse($SpecificOrderDetails)/SPECIFICORDERDETAILS/ORDERROW[ACTION ='0']"/>
Thanks everyone for helping!
Related
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.
I am getting a JSON using AJAX in AngularJS. One of the attributes in the object (say, sample), has a string "<b>String</b>".
I populate this into a table as follows:
<td>{{item.sample}} </td>
This gives an output: <b>String</b> on the webpage, when I was actually trying to display String.
Since it is a JSON string, what is currently happening makes sense. How do I use this string and somehow evaluate it so that I see the bold string on the webpage?
Use ngBindHtml directive to render your text.
<td ng-bind-html="item.sample"></td>
I have a table in HTML. In one row, I have numerous data like name, email, URL, date, etc:
<td>
15
</td>
<td>2017-07-18 11:00</td>
<td>Teszt SK</td>
<td>Test Trevor<small></small></td>
<td>2017-07-18 12:00</td>
<td><span class="label label-primary">Already in</span></td>
I wish to get the last part of the URL where the name equals my ${name} variable.
The URL looks like: http<nolink>://mywerbsite.com/event/123
So what I wish to get is the 123 and put it into my ${eventid} variable.
The problem is the fact, that there are usually more than one events for the users. So I want JMeter to stop at the first found. How do I do that?
The relevant XPath Expression would be something like:
substring-after(//td[text()='Test Trevor']/parent::*/td/a/#href,'events/')
Demo:
References:
XSLT, XPath, and XQuery Functions
XPath substring-after function reference
Using the XPath Extractor in JMeter
Add regular expression as post processor of request
regular expression: mywebsite.com/events/(\d+)" (.*)Test Trevor
Template $1$
Match No. 1
It will return the first row (checked)
Well, after a few tries, I've came up with a quite complicated answer but it sure works. Some minor tweaks are still needed, but it works. Here are some screenshots.
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
I have to produce an xquery file using normalize text and lower case Xpath function. (that is the page which includes the schema that my query must process: http://www.natcorp.ox.ac.uk/docs/URG/bnctags.html) I must put it in a table and I do not know who to produce a HTML table with xquery and I do not know also who to link xquery with xpath.
(That is the specification of my exercise)
Produce a .xquery file containing a XQuery FLWOR expression which returns all the
occurrences of the word 'has' in the collection of files, together with the word which comes next in the sentence in each case. The resulting list should be formatted as a HTML table, with each row containing the two words in their own cells, e.g.:
Target Successor
has there
has n't
has n't
... ...
Try something like the following, with the main thing being to figure out the proper pattern match. let $seek := "has", $pattern := concat($seek,"(\s?[^\s])") return <table> <tr><th>Target</th><th>Successor</th> { for $item in //text()[contains(.,'has')] let $match := string($item) return <tr> <td>{replace($match,$pattern,"$1")}</td> <td>{replace($match,$pattern,"$2")}</td> </tr> } </table>