YQL column projection using XPATH - yql

This query:
SELECT *
FROM html
WHERE url='http://wwww.example.com'
AND xpath='//tr[#height="20"]'
returns XML:
<results>
<tr height="20">
<td height="20" width="425">
<p>Institution 0</p>
</td>
<td width="134">
<p>Minneapolis</p>
</td>
<td width="64">
<p>MN</p>
</td>
</tr>
...
</results>
Questions:
Is there a way to use XPATH to create individual columns?
Is there a way to create column aliases?
Example (invalid syntax):
SELECT td[position()=1]/p/. AS name, td[position()=2]/p/. AS city, td[position()=3]/p/. AS region
FROM ...
Goal:
<results>
<tr height="20">
<name>Institution 0</name>
<city>Minneapolis</city>
<region>MN</region>
</tr>
...
</results>

Not with XPath, as you are trying to do. However one can apply XSL Transformations to XML/HTML documents with YQL. Here's an example:
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<rows>
<xsl:apply-templates select="descendant::tr" />
</rows>
</xsl:template>
<xsl:template match="//tr">
<row>
<name>
<xsl:value-of select="td[1]/p" />
</name>
<city>
<xsl:value-of select="td[2]/p" />
</city>
<region>
<xsl:value-of select="td[3]/p" />
</region>
</row>
</xsl:template>
</xsl:stylesheet>
HTML
<html>
<body>
<table>
<tr height="20">
<td height="20" width="425">
<p>Institution 0</p>
</td>
<td width="134">
<p>Minneapolis</p>
</td>
<td width="64">
<p>MN</p>
</td>
</tr>
<tr height="20">
<td height="20" width="425">
<p>Institution 1111</p>
</td>
<td width="134">
<p>Minneapolis 1111</p>
</td>
<td width="64">
<p>MN 11111</p>
</td>
</tr>
</table>
</body>
</html>
YQL query
select * from xslt where stylesheet="url/to.xsl" and url="url/to.html"
YQL Result
<results>
<rows>
<row>
<name>Institution 0</name>
<city>Minneapolis</city>
<region>MN</region>
</row>
<row>
<name>Institution 1111</name>
<city>Minneapolis 1111</city>
<region>MN 11111</region>
</row>
</rows>
</results>
ยป See an example running in the YQL console.

Related

Tiles 3 override a nested attribute

I'm have a problem with Tiles 3 with Struts2. I can't seem to override an attribute of a nested tiles-definition.
Here's the relevant parts of my web.xml:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
Here's my struts.xml
<package name="helloworld" extends="tiles-default" namespace="/secure">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" default="true" />
</result-types>
<interceptors>
<interceptor name="s2sLogging" class="com.s2s.web.s2.S2Interceptor" />
<interceptor-stack name="s2sStack">
<interceptor-ref name="timer" />
<interceptor-ref name="defaultStack" />
<interceptor-ref name="s2sLogging" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="s2sStack" />
<action name="howitworks" class="com.s2s.web.s2.S2RootAction" >
<result name="success" type="tiles">.howItWorks.landing</result>
</action>
Here's my tiles.xml
<definition name="s2s.rightNav" template="/WEB-INF/s2/pages/common/rightNav.jsp" >
</definition>
<definition name="s2s.pageContent" template="/WEB-INF/s2/pages/pageContent.jsp">
<put-attribute name="box" value="true" /> <!-- change to false to remove grey box behind text -->
<put-attribute name="rightNav" value="s2s.rightNav" />
</definition>
<!-- overall page layout -->
<definition name="page.layout" template="/WEB-INF/s2/pages/page.jsp">
<put-attribute name="pageTitlePrefix" value="s2s.com" type="string"/>
<put-attribute name="pageTitle" value=" " type="string"/>
<put-attribute name="headContent" value="s2s.headContent" />
<put-attribute name="extraHeadContent" value=".tile.empty" />
<put-attribute name="topNav" value="s2s.topNav" />
<put-attribute name="topNavSubNav" value="s2s.topNavSubNav" />
<put-attribute name="pageContent" value="s2s.pageContent" />
<put-attribute name="footer" value="s2s.footer" type="string"/>
<put-attribute name="SEOkeywords" value="s2s, ship to storage, moving storage services, self-storage, moving storage, self storage shipping, send to storage, ship to self storage, shipping storage, mail storage, self storage pick up and delivery" />
<put-attribute name="SEOdescription" value="The worlds most convenient self-storage. s2s combines shipping, elf storage, and service -- prices from $2.79 a box. Boxes are picked up from your doorstep and stored at our climate controlled, secure warehouse. s2s's flexible pricing grows as your needs grow. A valuable shipping and storage resource for moving, relocation, offices, students, trade shows, and more." />
<put-attribute name="pageSEOkeywords" value=" " type="string"/>
<put-attribute name="pageSEOdescription" value="s2s.com - " type="string"/>
<put-attribute name="debugPage" value="v.101" type="string"/>
</definition>
<!-- PAGE DEFNINITIONS -->
<definition name=".howItWorks.landing" extends="page.layout">
<put-attribute name="pageTitle" value="How Mail Storage Works " type="string"/>
<put-attribute name="selectedTab" value="howItWorks" type="string"/>
<put-attribute name="pageSEOkeywords" value="how it works, " type="string"/>
<put-attribute name="pageSEOdescription" value="How It Works | " type="string"/>
<put-attribute name="rightNavCTAs" value="estimateBoxSize,helpfulLinks" type="string" cascade="true"/>
<put-attribute name="mainBodyContent" value="s2s.howItWorks.MainBodyContent" cascade="true"/>
</definition>
<definition name="s2s.howItWorks.MainBodyContent" template="/WEB-INF/s2/pages/howItWorks.jsp" />
I want to override the mainBodyContent and the rightNavCTAs attributes of with the definition of .howItWorks.landing. However, when I print out the actual value in the jsp , rightNavCTAs is null (and I think it means that the value is not propagating down even though I use cascade="true").
According to the Apache Tiles 3 documentation here, I should be able to nest using subdefinitions like I have above, and then extend and override attributes. The cascade is supposed to propagate attributes.
Needless to say, I can't get it to work. Can anyone spot my flaw?
as Requested, here are my jsps. thanks for looking.
all jsps have this at the top:
<%# page contentType="text/html; charset=UTF-8" %>
<%# taglib prefix="s" uri="/struts-tags" %>
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
Here is My page.jsp (stripped of css):
<tiles:importAttribute scope="request"/>
<html>
<head>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/stylesheet.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/jmesa.css">
<title>
<tiles:getAsString name="pageTitlePrefix" /> - <tiles:getAsString name="pageTitle" />
</title>
<tiles:insertAttribute name="headContent" />
<tiles:insertAttribute name="extraHeadContent" />
</head>
<body>
<div id="page">
<tiles:insertAttribute name="topNav" />
<tiles:insertAttribute name="topNavSubNav" />
<tiles:insertAttribute name="pageContent" />
<tiles:insertAttribute name="footer" />
</div>
</body>
</html>
Here is may pageContent.jsp (stripped of css):
<table >
<tr>
<td >
<!-- Box Table Starts here-->
<s:if test="%{#attr['box'] == 'true'}">
<table >
<tr>
<td /></td>
<td /></td>
<td /></td>
</tr>
<tr>
<td > </td>
<td >
<!-- Insert Main Body Content1 -->
<tiles:insertAttribute name="mainBodyContent" />
<!-- End of Main Body Content1 -->
</td>
<td > </td>
</tr>
<tr>
<td /></td>
<td > </td>
<td /></td>
</tr>
</table>
</s:if>
<s:else>
<!-- Insert Main Body Content -->
<tiles:insertAttribute name="mainBodyContent" />
<!-- End of Main Body Content -->
</s:else>
</td>
<td > </td>
<td >
<tiles:insertAttribute name="rightNav" />
</td>
</tr>
</table>
<!-- End Page Content -->
And here is my howitworks.jsp (again, stripped of css). This is supposed to override the mainBodyContent attribute, but I can't get it to work :
<table >
<tr>
<td />Test... how it works</td>
<td /></td>
<td /></td>
</tr>
</table>

How to show PASSED tests in Jenkins test results

Once Jenkins job is done it will display all and failed tests but there are no passed tests. I need this for my mail notification. It would be more convenient for me to have here a list of all passed tests:
enter image description here
Allow me to answer to myself: You just need to update a bit existing html emial notification: https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/resources/hudson/plugins/emailext/templates/html.jelly
Read this also to know where to put new file:
https://wiki.jenkins-ci.org/pages/viewpage.action?pageId=59506969
Copy this part of file
<!-- JUnit TEMPLATE -->
<j:set var="junitResultList" value="${it.JUnitTestResult}" />
<j:if test="${junitResultList.isEmpty()!=true}">
<TABLE width="100%">
<TR><TD class="bg1" colspan="2"><B>JUnit Tests</B></TD></TR>
<j:forEach var="junitResult" items="${it.JUnitTestResult}">
<j:forEach var="packageResult" items="${junitResult.getChildren()}">
<TR><TD class="bg2" colspan="2"> Name: ${packageResult.getName()} Failed: ${packageResult.getFailCount()} test(s), Passed: ${packageResult.getPassCount()} test(s), Skipped: ${packageResult.getSkipCount()} test(s), Total: ${packageResult.getPassCount()+packageResult.getFailCount()+packageResult.getSkipCount()} test(s)</TD></TR>
<j:forEach var="failed_test" items="${packageResult.getFailedTests()}">
<TR bgcolor="white"><TD class="test_failed" colspan="2"><B><li>Failed: ${failed_test.getFullName()} </li></B></TD></TR>
</j:forEach>
</j:forEach>
</j:forEach>
</TABLE>
<BR/>
</j:if>
paste it again and change it slightly:
<!-- JUnit TEMPLATE -->
<j:set var="junitResultList" value="${it.JUnitTestResult}" />
<j:if test="${junitResultList.isEmpty()!=true}">
<TABLE width="100%">
<TR><TD class="bg1" colspan="2"><B>JUnit Tests</B></TD></TR>
<j:forEach var="junitResult" items="${it.JUnitTestResult}">
<j:forEach var="packageResult" items="${junitResult.getChildren()}">
<TR><TD class="bg2" colspan="2"> Name: ${packageResult.getName()} Failed: ${packageResult.getFailCount()} test(s), Passed: ${packageResult.getPassCount()} test(s), Skipped: ${packageResult.getSkipCount()} test(s), Total: ${packageResult.getPassCount()+packageResult.getFailCount()+packageResult.getSkipCount()} test(s)</TD></TR>
<j:forEach var="passed_test" items="${packageResult.getPassedTests()}">
<TR bgcolor="white"><TD class="test_passed" colspan="2"><B><li>Passed: ${passed_test.getFullName()} </li></B></TD></TR>
</j:forEach>
</j:forEach>
</j:forEach>
</TABLE>
<BR/>
</j:if>

accessing different servers (urls) using selenium ide

I've a requirement to hit a url of server x, click a submit button and jump to same url of server y and click the same submit button and this has to be repeated 26 times as I've to change on 26 servers.
All this I have to do selenium ide. I managed to do this for 1 server but just wondering if there is a smart way to do this for 26 servers rather recording 26 times.
I'm using selenium 2.9.0 IDE plugin with firefox browser
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://server-x:9173/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>website/delivery/DeliveryMethodsRepository/</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=DeliveryMethodsRepository/</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=invalidateCaches</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>name=submit</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=DeliveryMethodsRepository/</td>
<td></td>
</tr>
</tbody></table>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>inventory/InventoryRepository/</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=InventoryRepository/</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=invalidateCaches</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>name=submit</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=InventoryRepository/</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
You can keep base url as "http://". You then need to use readCSV for all server urls and while loop for repeating for number of servers.
Please refer [http://bashamy.blogspot.co.uk/2016/01/selenium-ide-to-use-while-loop-and-read.html] for more information.
Edit Url: http://bashamy.blogspot.com/2016/01/selenium-ide-to-use-while-loop-and-read.html
Eg: Below html code opens 5 different urls from my CSV input file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://onlineconversion.com/" />
<title>06 ReadCsv_n_Loop</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">06 ReadCsv_n_Loop</td></tr>
</thead><tbody>
<tr>
<td>readCSV</td>
<td>file://C:\Users\extayx\Documents\Selenium IDE\07Input.csv</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>row</td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>col</td>
</tr>
<tr>
<td>store</td>
<td>6</td>
<td>z</td>
</tr>
<tr>
<td>while</td>
<td>${row}<${z}</td>
<td></td>
</tr>
<tr>
<td>storeCellValue</td>
<td>ip</td>
<td>${row},${col}</td>
</tr>
<tr>
<td>echo</td>
<td>${ip}</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${ip}</td>
<td>${ip}</td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['row'] = ${row}+1</td>
<td>x</td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
My input CSV file has below information.
www.google.co.in
www.google.com
www.google.co.uk
www.news.google.co.in
www.seleniumhq.org
Your question is very confusing, so I probably misunderstood it.
In the unlikely case I got it right, you're trying to do the same task for different websites 26 times. Sounds like something a loop could do.
Here's a sample Python code:
urls = ['http://foo.bar', 'http://otherfoo.otherbar',...]
for url in urls:
driver.get(url)
#your selenium code here
This is something I have had to do myself, and is possible using a set of plugins called selite or also selblocks (although selite contains a version of this plugin already)
With these plugins it will allow you to save the list of URLs as an external json file, then to loop the test case you will just need to put the 'Forjson' command calling the file at the stage where you want your loop to begin, and the 'Endforjson' where you want it to end. All the documentation is in the link. Hope it helps.

XSLT current-groups() issue

I've been having a bit of trouble with an HTML file that I'm trying to translate. Basically, the relevant part of the source structure as it currently stands is this:
<h2 />
<h3 />
<table />
<table />
<h3 />
<table />
<table />
<h3 />
<table />
<h3 />
<h3 />
<table />
<table />
<h2 />
<h3 />
...
and so on. Each of the contents of these are being translated in different ways, but the problem I'm currently having is in grouping them correctly. Essentially, I want it to end up like the following:
<category>
<h2 />
<container>
<h3 />
<table />
<table />
</container>
<container>
<h3 />
<table />
<table />
</container>
<container>
<h3 />
<table />
</container>
<container>
<h3 />
</container>
<container>
<h3 />
<table />
<table />
</container>
</category>
<category>
<h2 />
<container>
<h3 />
...
to achieve this, I've been using the following code:
<xsl:for-each-group select="node()"group-starting-with="xh:h2">
<category>
<xsl:apply-templates select="xh:h2"/>
<xsl:for-each-group select="current-group()"
group-starting-with="xh:h3">
<container>
<xsl:apply-templates select="current-group()[node()]"/>
</container>
</xsl:for-each-group>
</category>
</xsl:for-each-group>
However, the output I get from this is as follows:
<category>
<h2 />
<container>
<h3 />
<table />
<table />
<h3 />
<table />
<table />
<h3 />
<table />
<h3 />
<h3 />
<table />
<table />
</container>
</category>
<category>
<h2 />
<container>
<h3 />
...
The first for-loop function is working as expected, however the second does not appear to be. If I use <xsl:copy-of> to output the first element in the <current-group> in the second for-loop, it shows the <h2> element, where that element should not even be in the group.
If anyone can point out where I'm going wrong, or offer a better solution, it would be greatly appreciated.
I think you want to change
<xsl:for-each-group select="node()" group-starting-with="xh:h2">
<category>
<xsl:apply-templates select="xh:h2"/>
<xsl:for-each-group select="current-group()"
group-starting-with="xh:h3">
to
<xsl:for-each-group select="*" group-starting-with="xh:h2">
<category>
<xsl:apply-templates select="."/>
<xsl:for-each-group select="current-group() except ."
group-starting-with="xh:h3">
That way the inner for-each-group processes the h3 and table elements but no the h2 element starting the outer group.
If you need more help then consider to post small but complete samples with namespaces present allowing us to reproduce the problem with the undesired output.
I think you've simplified the problem and in doing so have introduced some red herrings.
The xsl:apply-templates select="h2" surely does nothing, because none of the nodes selected in the outer grouping has an h2 child.
In every group selected by the outer for-each-group, except the first, the first node in the group will be an h2 element, by definition. Your inner for-each-group will partition the sequence of nodes starting with an h2 into: first, a group that starts with the h2 (because every node becomes part of some group), and then a sequence of groups each of which starts with an h3. You need to split out the first (non-h3) group and treat it differently, because you don't want to generate a container element in this case. So you need an xsl:choose in the inner for-each-group, typically with the condition xsl:when test="self::h2" to detect that you're processing the special first group.
Having said all that I can't see why you aren't getting a container element for each h3 element. I think this must be caused by something that you haven't shown us (perhaps a namespace issue?)

Grouping in XSLT 2.0 similar to br to p problems

In XSLT 1.0, a common question in forums was how to convert flat HTML into hierarchical XML, which many times boiled down to nesting text in between <br /> tags in <p> tags.
I have a similar problem, which I think I've partially solved using XSLT 2.0, but it's a new approach to me and I'd like to get a second opinion.
The XHTML source has <span class="pageStart"></span> scattered throughout. They can appear in several different parent nodes. I want to wrap all the nodes between one page start marker and the next in an <page> node. The solution I currently have is:
<xsl:template match="*[child::span[#class='pageStart']]">
<xsl:copy>
<xsl:copy-of select="#*" />
<xsl:for-each-group select="node()"
group-starting-with="span[#class='pageStart']">
<page>
<xsl:apply-templates select="current-group()"/>
</page>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
There's at least one flaw with this -- the parent node of the marker gets a <page> as a child node when I don't want it. In other works, if there's a <div> that has a child page marker anywhere in it, an <page> node is created as an immediate child of <div> in addition to the locations I expect.
I had hoped that I could simply make the template rule be <xsl:template match="span[#class='pageStart']"> but current-group() seems to be empty no matter what I try. The common sense approach I tried was <xsl:for-each-group select="node()" group-starting-with="span[#class='pageStart']">.
Is there an easier way to solve this problem that I'm missing?
EDIT
Here's an example of the input:
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head></head>
<body>
<span class="pageStart"/>
<p>...</p>
<div>...</div>
<img />
<p></p>
<span class="pageStart"/>
<div>...</div>
<span class="pageStart"/>
<p>...</p>
<div>
<span class="pageStart"/>
<p>...</p>
<p>...</p>
<span class="pageStart"/>
<div>...</div>
<img/>
</div>
</body>
</html>
I assume the last two nested pages make this problem more difficult, so I'd be perfectly happy getting this as the output, or something close:
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head></head>
<body>
<page>
<span class="pageStart"/>
<p>...</p>
<div>...</div>
<img />
<p></p>
</page>
<page>
<span class="pageStart"/>
<div>...</div>
</page>
<page>
<span class="pageStart"/>
<p>...</p>
<div>
<page>
<span class="pageStart"/>
<p>...</p>
<p>...</p>
</page>
<page>
<span class="pageStart"/>
<div>...</div>
<img/>
</page>
</div>
</page>
</body>
</html>
This transformation:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[span/#class='pageStart']">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:for-each-group select="node()"
group-starting-with="span[#class='pageStart']">
<page>
<xsl:apply-templates select="current-group()"/>
</page>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document:
<html>
<head></head>
<body>
<span class="pageStart"/>
<p>...</p>
<div>...</div>
<img />
<p></p>
<span class="pageStart"/>
<div>...</div>
<span class="pageStart"/>
<p>...</p>
<div>
<span class="pageStart"/>
<p>...</p>
<p>...</p>
<span class="pageStart"/>
<div>...</div>
<img/>
</div>
</body>
</html>
produces the wanted, correct result:
<html>
<head/>
<body>
<page>
<span class="pageStart"/>
<p>...</p>
<div>...</div>
<img/>
<p/>
</page>
<page>
<span class="pageStart"/>
<div>...</div>
</page>
<page>
<span class="pageStart"/>
<p>...</p>
<div>
<page>
<span class="pageStart"/>
<p>...</p>
<p>...</p>
</page>
<page>
<span class="pageStart"/>
<div>...</div>
<img/>
</page>
</div>
</page>
</body>
</html>

Resources