XSLT set empty to xsl value of - xslt-2.0

How to set to a empty value.
I have a
<td>
<xsl:value of select="">
</td>.
That td should contain an empty value.

Just use <td> </td>

just use
<xsl:value-of select="''"/>

Related

Accessing the name of a smarty variables

Hello i need some help with a basic question. This is my code:
{foreach $sArticle.attributes.core->toArray() as $attribute}
<tr class="product--properties-row">
<td class="product--properties-label is--bold">{$sArticle.attributes.name}{$sArticle.attributesName}</td>
<td class="product--properties-label is--bold">{$attribute}</td>
</tr>
{/foreach}
1.Question: How do I enter the attributes name? I mean the column name from the attribute in the database?
2.Question: I only want to loop with the foreach through columns with name="artikelattr_" any idea how this can be done?
Thanks
I adjusted my answer here: https://stackoverflow.com/a/71237355/7201069
How to get the name of the attribute.
To consider only certain attributes that starts with a specific string, just add an if in the loop:
{foreach $sArticle.attributes.core->toArray() as $attributeName => $attribute}
{if $attributeName|strpos:"artikelattr_" === 0}
{$attributeName|var_dump}
{$attribute|var_dump}
{/if}
{/foreach}
You can simply use nearly all PHP functions in Smarty.

Struts2 Iterator Tag

I am migrating my application from Struts-1 to Struts-2.
The following piece of code uses Struts-1 iterate tag to iterate over a collection "myFormBeanCollection".
Here myFormBean is the form bean,
myFormBeanCollection is one property of myFormBean and is of type ArrayList, this list holds the objects of type "com.xyz.SomeClass".
And next comes a scriptlet element, and then some bean:write...
In scriptlet code: getDate() method is defined in "com.xyz.SomeClass".
<logic:iterate name="myFormBean" property= "myFormBeanCollection" id="someId" type="com.xyz.SomeClass">
<%
String startDate = dateFormat.format(someId.getDate());
%>
<td width="13%" align="center">
<%=startDate%>
</td>
<td width="8%" align="center">
<bean:write name="someId" property="prop_1" />
</td>
</logic:iterate>
How can I migrate this particular code to Struts-2.
I tried using Struts2 iterator tag.
But couldn't succeed in writing the scriptlet.
Not sure on how to call "getDate()" method in the scriptlet as how it was done in above code(Struts-1).
<s:iterator value="myFormBean.myFormBeanCollection">
<%
String startDate = dateFormat.format(""); // Not sure on how to call "getDate()" method as how it was done in above code(Struts-1).
%>
<s:property value="countryName" />,
</s:iterator>
Any help would be greatly appreciated.
Thanks,
Sunil
You wou'dn't, you'd use the <s:date /> tag:
<s:date name="date" format="whatever" />
In fairness, you didn't need to use scriptlet in the original version either--the less work you do in Java in JSP the better: stick to HTML and tags only.
Instead of blindly re-writing the exact same way try to make structural and technical improvements.

Convert thymeleaf to freemarker

Please help, i cann't find in freemarker guide how to convert from thymeleaf this:
lists.isEmpty and for each
<th:block th:if="${#lists.isEmpty(employees)}">
<h3>No employee</h3>
</th:block>
<th:block th:unless="${#lists.isEmpty(employees)}">
<tr th:each="contact,iterStat : ${employees}">
<td th:text="${iterStat.count}"></td>
<td th:text="${contact.name}"></td>
<td th:text="${contact.phone}"></td>
Thanks!
Maybe Something like this? (sketch, not tested)
<#list employees as contact>
<tr>
<td>${contact?index}
<td>${contat.name}</td>
<td>${contact.phone}</td>
</tr>
<#else>
<h3>No employee</h3>
</#list>
Notes
<#list> Will generate a <tr> element for each item in the employees sequence, containing <td>'s for each field.
If the employees sequence is empty it will generate the <h3> element.
See List Directive Doc
It gets the zero based index of the item using the build-in function
?index. See built-ins and loop variables in the help. Freemarker built-ins Doc. If you want one based, you can add one to it.
It's works
<#list employees as contact>
<tr>
<td>${contact?index}
<td>${contat.name}</td>
<td>${contact.phone}</td>
</tr>
<#else>
<h3>No employee</h3>
</#list>

Thymeleaf - how to condition format date value if exists?

I have a table that shows dates, but some date values are null or blank. I'd like to format them if they exist and display nothing if there's no value.
I was considering something like:
(date != '' ? ${#calendars.format(date,'dd-MM-yyyy HH:mm')} : '')
Is this possible? How?
Maybe you have to try something like this?
<table>
....
<td>
<span th:if="${date != null}"
th:text="${#calendars.format(date,'dd-MM-yyyy HH:mm')}">
</span>
</td>
....
</table>
If you have not null value in date it will shown another it will be blank table cell.
The shortest way I think is this:
<td th:text="${#date} ? ${#calendars.format(date,'dd-MM-yyyy HH:mm')}" />

Hpple XPath query issue on IOS

I have the following HTML snippet:
<divv id="items">
<trr>
<td>
<p>Cars</p>
<a>Toyota</a>
<a>Opel</a>
<a>Audi</a>
</td>
</tr>
<tr>
<td>
<p>Planes</p>
<a>A320</a>
<a>B787</a>
<a>B767</a>
</td>
</tr>
<div/>
What I want is to create a XPath query so I can retrieve only the Cars.
Currently I am using this: //div[#id='items']/tr/td. But with this I get also the Plane items. I do not know how to test for the 'p' tag.
Anyone can help me ?
Thanks.
//div[#id='items']/tr/td[p='Cars']
The last predicate tests the existence of a <p> child element with Cars text content and thus filters out the <td> with <p>Planes</p>.
If picking the first group is enough, then you can use:
//div[#id='items']/tr/td[1]

Resources