xslt - grouping element and following element - xslt-1.0

I have the following structure. That is to say - I may have the following structure.
The output comes from a CMS and very often there is text in front of a table and after a table. In order to make the second stage in the transformation work, wrapping the the paragraph before the table and after the table inside an element is essential.
<?xml version="1.0" encoding="UTF-8"?>
<div>
<p>some text here</p>
<p>and maybe some text here. it may or may not be here</p>
<figure>
<table>
<tbody>
<tr>
<td>test</td>
</tr>
</tbody>
</table>
</figure>
<p>Likely to be a paragraph here</p>
<p>And here - often like: table 2, but nothing I can use</p>
<figure>
<table>
<tbody>
<tr>
<td>test</td>
</tr>
</tbody>
</table>
</figure>
<p>and another paragraph at the end of the table</p>
</div>
My goal is to get an output like below where the first paragraph in the beginning has it's own wrapper. then the combination of paragraph + table + paragraph is put inside a wrapper.
There might be some paragraphs at the end of the file and those should be wrapped as well.
<?xml version="1.0" encoding="UTF-8"?>
<body>
<div>
<p>some text here</p>
</div>
<div class="table">
<p>and maybe some text here. it may or may not be here</p>
<figure>
<table>
<tbody>
<tr>
<td>test</td>
</tr>
</tbody>
</table>
</figure>
<p>Likely to be a paragraph here</p>
</div>
<div class="table">
<p>And here - often like: table 2, but nothing I can use</p>
<figure>
<table>
<tbody>
<tr>
<td>test</td>
</tr>
</tbody>
</table>
</figure>
<p>another text at the end of the table</p>
</div>
</body>
I am playing around with preceding and following + parent. Any pointers in the right direction would be of great help
I am restricted to XSLT 1.0.

I don't think the problem is well-defined. Given certain assumptions (which should be self-evident), and given a well-formed input such as:
XML
<body>
<p>some text here</p>
<p>and maybe some text here. it may or may not be here</p>
<figure>
<table>
<tbody>
<tr>
<td>test</td>
</tr>
</tbody>
</table>
</figure>
<p>Likely to be a paragraph here</p>
<p>And here - often like: table 2, but nothing I can use</p>
<figure>
<table>
<tbody>
<tr>
<td>test</td>
</tr>
</tbody>
</table>
</figure>
<p>and another paragraph at the end of the table</p>
</body>
you could do something like:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="body">
<xsl:copy>
<xsl:apply-templates select="p[not(preceding-sibling::*[1][self::figure] or following-sibling::*[1][self::figure])]" mode="stand-alone"/>
<xsl:for-each select="figure">
<div class="table">
<xsl:copy-of select="preceding-sibling::*[1][self::p]"/>
<xsl:copy-of select="."/>
<xsl:copy-of select="following-sibling::*[1][self::p]"/>
</div>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="p" mode="stand-alone">
<div>
<xsl:copy-of select="."/>
</div>
</xsl:template>
</xsl:stylesheet>
to get:
Result
<body>
<div>
<p>some text here</p>
</div>
<div class="table">
<p>and maybe some text here. it may or may not be here</p>
<figure>
<table>
<tbody>
<tr>
<td>test</td>
</tr>
</tbody>
</table>
</figure>
<p>Likely to be a paragraph here</p>
</div>
<div class="table">
<p>And here - often like: table 2, but nothing I can use</p>
<figure>
<table>
<tbody>
<tr>
<td>test</td>
</tr>
</tbody>
</table>
</figure>
<p>and another paragraph at the end of the table</p>
</div>
</body>

Related

Materialize CSS Remove table head spacing

I making a simple demo where i have few employees information. I am using materialize css table. But i am getting extra space between sr.no and other column names.
here is my code :
<br/>
<div class="row">
<div class="col l8">
<div class="card darken-2">
<div class="card-content">
<span class="card-title">{{tableTitle}}</span>
<br/>
<div class="row">
<div class="input-field col s4">
<input id="empSearch" type="text" placeholder="Search">
</div>
</div>
<br/>
<div class="row">
<div class="col lg7">
<table class="bordered highlight responsive-table">
<thead>
<tr>
<th>Sr.no</th>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
<th>Address</th>
<th>Designation</th>
<th>Department</th>
<th>Salary</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of EmployeeData;let i= index">
<td>{{i+1}}</td>
<td>{{item.Name}}</td>
<td>{{item.Age}}</td>
<td>{{item.Gender}}</td>
<td>{{item.Address}}</td>
<td>{{item.Designation}}</td>
<td>{{item.Department}}</td>
<td>{{item.Salary}}</td>
<td>
<i class="material-icons">delete</i>
</td>
<td>
<i class="material-icons">mode_edit</i>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
in the <th> you could set width="30px" or whatever your're comfortable with.
The icons, I'd put in one cell, and use text-align: right
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.1/css/materialize.min.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<table>
<thead>
<tr>
<th width="30px">Sr.no</th>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
<th>Address</th>
<th>Designation</th>
<th>Department</th>
<th>Salary</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>{{i+1}}</td>
<td>{{item.Name}}</td>
<td>{{item.Age}}</td>
<td>{{item.Gender}}</td>
<td>{{item.Address}}</td>
<td>{{item.Designation}}</td>
<td>{{item.Department}}</td>
<td>{{item.Salary}}</td>
<td style="text-align: right">
<i class="material-icons">delete</i>
<i class="material-icons">mode_edit</i>
</td>
</tr>
</tbody>
</table>

I want to extract a text string on the webpage which is written in the form of table, but I am getting null in return

WebElement e5 = d1.findElementByXPath("/html/body/div[1]/div[3]/div/div[1]/form/div/div[1]/div/table/tbody/tr[4]/td[2]");
String a = e5.getText();
System.out.println(a);
_____________________________________________________________________________
I have used getText method. The data is stored in the table, so the strategy which I am making use of is that first of all i want to get to the location of that data using xPath funda and then I need to extract the data corresponding to that location. Can anyone suggest a better way to do so.Thanks in advance.
pls find below the html:
<div class="wrapper">
<form method="post" action="">
<input id="_csrf" type="hidden" value="psJdnI5AnxjGqT2knrZG" name="_csrf">
<div class="innercontainer">
<div class="leftpanel">
<h2>MY ACCOUNT</h2>
<div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<tr>
<td>
<strong>Membership ID:</strong>
</td>
<td>2800000101</td>
</tr>
<tr>
<tr>
<tr> </tr>
<tr>
</tbody>
</table>
</div>
</div>
<div class="rightpanel">
</div>
</form>
</div>
html page added above. Kindly suggest some alternative
You need to clean up your Xpath, however this should help
WebElement tableText = driver.findElement(By.xpath("yourXpath"));
String actualText = tableText.getAttribute("textContent");
System.out.println(actualText)

Getting elements from a webbrowser

Hoping someone can help me out here.
I'm trying to pull a few bits of info from a web page programatically.
The HTML in question is like this...
<body>
<!-- body content -->
<div id="content">
<!-- Page Header -->
<h1>
PRODUCTNAME™
</h1>
<!-- End Page Header -->
<div id="productImg">
<img id="product.image.large.015" alt="PRODUCTNAME™" src="PRODUCTIMAGEURL" border="0" />
</div>
<div id="productAlt">
<table width="98%" border="0" cellspacing="1" cellpadding="2">
<tr class="altRowLtGray">
<td>
Item #
<span style="text-decoration: inherit;">015</span>
</td>
</tr>
<tr class="altRowLtGray">
<td>
<span style="float: left;">PRODUCTPRICE GBP</span>
<span style="float: right; padding-left: 1em;"></span>
</td>
</tr>
<tr class="altRowLtGray">
<td>
PRODUCTADDITIONALINFO
</td>
</tr>
</table>
</body>
I need to retrieve the 4 items in caps (PRODUCTNAME, PRODUCTIMAGEURL, PRODUCTPRICE and PRODUCTADDITIONALINFO) but am struggling as any examples I find dont seem to be able to be transposed to suit the above HTML... but it could just be me!
I know I need to use either GetElementByID or GetElementByTagName, but i've not used either of these functions before so please forgive my ignorance.
Any help appriciated!!!

Any Dijit component is rendered as TextField

Please find my code which intents to develop a Form. Help me in understanding why the CheckBox and NumberSpinner are rendered as TextFields.
I have imported all the required classes and dojo config attribute is configured properly
<%# taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%# taglib prefix="fmt" uri=`enter code here`"http://java.sun.com/jstl/fmt" %>
<%#include file="/webclient/admin/jspf/NotificationOperations.jspf" %>
<!-- load dojo and provide config via data attribute -->
<script type="text/javascript" src="/webclient/map/js/dojo/dojo.js" data-dojo-config="parseOnLoad: true"></script>
<script>
require([
"dojo/parser",
"dijit/form/CheckBox",
"dijit/form/NumberSpinner",
"dojo/domReady!"
], function(parser){
parser.parse();
});
</script>
<%#include file="/webclient/common/jspf/jsUtility.jspf" %>
<html>
<head>
<body class="claro">
<style>
#import "/webclient/common/js/dojo/dgrid/css/skins/claro.css";
h2 {
margin: 12px;
}
.heading {
font-weight: bold;
padding-bottom: 0.25em;
}
.ui-widget{
margin: 10px;
}
</style>
<table width="100%" height="100%">
<tr><td>
<div id="DomainMapContainer" >
<tr class="spacer"><td> </td></tr>
<tr><td>
<form id="addProfile" data-dojo-type="dijit/form/Form" data-dojo-props='encType:"multipart/form-data", action:"/prov/createRFC2544TestProfile.do?action=createRFC2544TestProfile", method:"POST", target:"formSubmitIframe"'>
<table>
<tr>
<td><label for="profileName">Profile Name</label></td>
<td>
<input data-dojo-type="dijit/form/TextBox" data-dojo-props='id:"profileName", name:"profileName", required:"true"'/>
</td>
</tr>
<tr>
<td><label for="comments">Comments</label></td>
<td>
<input data-dojo-type="dijit/form/TextArea" data-dojo-props='id:"comments", name:"comments", rows:"5", cols:"40"'/>
</td>
</tr>
<tr>
<td><label for="frameSize">Frame Size</label></td>
<td>
<table>
<tr>
<td><label for="cb_1"><input data-dojo-type="dijit/form/CheckBox" id="cb_1" name="cb_1" value="64" checked/> 64</label></td>
<td><label for="cb_2"><input data-dojo-type="dijit/form/CheckBox" id="cb_2" name="cb_2" value="128"/> 128</label></td>
</table>
</td>
</tr>
</table>
<fieldset>
<legend><label> Throughput Test</label></legend>
<table>
<tr>
<td><label for="tTestDuration">Test Duration</label></td>
<td><input data-dojo-type="dijit/form/NumberSpinner" id="tTestDuration" value="60" data-dojo-props="smallDelta:1, constraints:{min:1,max:600,places:0}" name="tTestDuration"/>(Seconds)</td>
</tr>
<tr>
<td><label for="tTestMinFrameRate">Minimum Frame Rate</label></td>
<td><input data-dojo-type="dijit/form/NumberSpinner" id="tTestMinFrameRate" value="0" data-dojo-props="smallDelta:1, constraints:{min:1,max:10000,places:0}" name="tTestMinFrameRate"/>(Mbps)</td>
</tr>
<tr>
<td><label for="tTestMaxFrameRate">Maximum Frame Rate</label></td>
<td><input data-dojo-type="dijit/form/NumberSpinner" id="tTestMaxFrameRate" value="100" data-dojo-props="smallDelta:1, constraints:{min:1,max:10000,places:0}" name="tTestMaxFrameRate"/>(Mbps)</td>
</tr>
<tr>
<td><label for="tTestStepSize">Step Size</label></td>
<td><input data-dojo-type="dijit/form/NumberSpinner" id="tTestStepSize" value="5" data-dojo-props="smallDelta:1, constraints:{min:1,max:100,places:0}" name="tTestStepSize"/>(Mbps)</td>
</tr>
<tr>
<td><label for="tTestAcceptableLoss">Step Size</label></td>
<td><input data-dojo-type="dijit/form/NumberSpinner" id="tTestAcceptableLoss" value="0" data-dojo-props="smallDelta:0.1, constraints:{min:0,max:10,places:0}" name="tTestAcceptableLoss"/>(%)</td>
</tr>
</table>
</fieldset>
</form>
</td></tr>
</div>
</td></tr>
</table>
</body>
</head>
</html>
I'm seeing a few things here, first of all you're missing a closing </tr> tag when you close the "frame size" table. I suppose that it won't cause errors, but you can never be too sure.
You're also closing your </head> tag at the bottom of the page. You should close it before the <body> starts.
Then the real problem is that your widgets are not working because there are errors while parsing your HTML. The cause of the error is the "comments" text area. The correct module name you should use is dijit/form/Textarea, so the "a" of area should be in lowercase.
Besides that, you should also add the dijit/form/Textarea module to your list of modules (in your require() block).
If you did all that it should work, as you can see in this fiddle: http://jsfiddle.net/9U5AB/

Displaying tables based on multiple conditions in XSLT

I have five values that come from a form; like state1, state2, state3, state4, and state5.
Each value can be either 'New' or 'Closed'.
A Report will be displayed based on these values.
So, I created 5 tables, one each to be displayed on the report.
If a value is 'New' then display the respective table else no need to display.
So, I created XSLT like the below (this is just a fragment from my code).
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" omit-xml-declaration="yes" standalone="yes" indent="yes"cdata-section-elements="script msxsl:script"></xsl:output>
<xsl:template match="/">
<html>
<head><title>Report</title></head>
<body>
<table class="row1">
<tr>
<td align="left" colspan="2">
<img src="../images/Logos/logo.gif" height="80"></img>
</td>
</tr>
</table>
<xsl:if test="(state1='New') and (state2='Closed') and (state3='Closed') and (state4='Closed') and (state5='Closed')">
<table class="row2">
<tr>
<td class="section" uniqueID="ms__id17">
<b>Details(S1)</b>
</td>
</tr>
<!--some rows -->
</table>
</xsl:if>
<xsl:if test="(state1='New') and (state2='New') and (state3='Closed') and (state4='Closed') and (state5='Closed')">
<table class="row2">
<tr>
<td class="section" uniqueID="ms__id18">
<b>Details(S1)</b>
</td>
</tr>
<!--some rows -->
</table>
<table class="row3">
<tr>
<td class="section" uniqueID="ms__id19">
<b>Details(S2)</b>
</td>
</tr>
<!--some rows -->
</table>
</xsl:if>
<!--more conditions-->
</body>
</html>
</xsl:template>
</xsl:stylesheet>
If I keep on giving conditions like this I should give 5! conditions.
Is there a better way of doing this.
Is this what you want (use or instead of and)?
<xsl:if test="(state1='New') or (state2='New') or (state3='New') or (state4='New') or (state5='New')">
<table class="row2">
<tr>
<td class="section" uniqueID="ms__id17">
<b>Details(S1)</b>
</td>
</tr>
<!--some rows -->
</table>
</xsl:if>