List from repeated items in XSLT - arrays

I'm new to XSLT and I'm looking for help in my problem. Here is my code in XML:
<?xml version="1.0" encoding="UTF-8"?>
<nadrazi jmeno="Podlešín">
<vlak typ="os" cislo="5112" z="Hostivice" cil="Podlešín" naVlak="53001">
<prijezd>16:20:00</prijezd>
<slozeni>
<vuz cislo="1" oznaceniC="810" />
<vuz cislo="2" oznaceniC="010" oznaceniT="Btax" />
</slozeni>
</vlak>
<vlak typ="os" cislo="53001" z="Podlešín" smer="Zloněves" cil="Kralupy nad Vltavou" zVlaku="5112">
<odjezd>17:00:00</odjezd>
<slozeni>
<vuz cislo="1" oznaceniC="810" />
<vuz cislo="2" oznaceniC="010" oznaceniT="Btax" />
</slozeni>
</vlak>
<vlak typ="sp" cislo="1389" z="Louny" smer="Zloněves" cil="Praha Holešovice">
<prijezd>16:18:00</prijezd>
<odjezd>16:23:00</odjezd>
<slozeni>
<vuz cislo="1" oznaceniC="843" />
<vuz cislo="2" oznaceniT="Btn" />
<vuz cislo="3" oznaceniT="Btn" />
</slozeni>
</vlak>
<vlak typ="r" cislo="572" z="Praha Holešovice" smer="Slaný předměstí" cil="Chomutov">
Nechranice
<prijezd>14:27:00</prijezd>
<odjezd>14:28:00</odjezd>
<slozeni>
<vuz cislo="0" oznaceniC="754" />
<vuz cislo="250" oznaceniT="B" />
<vuz cislo="251" oznaceniT="B" />
<vuz cislo="252" oznaceniT="Bp" />
<vuz cislo="253" oznaceniT="Bp" />
<vuz cislo="254" oznaceniT="BDs" />
<vuz cislo="255" oznaceniT="A" />
</slozeni>
</vlak>
</nadrazi>
I want get a vlaue from all elements vlak attribute smer make an array (or a list or something similar) from this values and then use something like unique() function to have only one item of every repeated value. In this case in my array will be "Zloněves" and "Slaný předměstí".
Here is my XSLT code. I tried some ways to create some arrays but I failed and erased that lines (some time ago).
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" />
<xsl:template match="/">
<html>
<head>
<title>Rozpis vlaků pro stanici <xsl:value-of select="nadrazi/#jmeno" /></title>
</head>
<script type="text/javascript">
function show(element) {
var srcElement = document.getElementById(element);
if(srcElement != null) {
if(srcElement.style.display == "block") {
srcElement.style.display= 'none';
} else {
srcElement.style.display='block';
}
return false;
}
}
</script>
<body>
<h1>Stanice <xsl:value-of select="nadrazi/#jmeno" /></h1>
<xsl:apply-templates select="nadrazi" mode="smer" />
</body>
</html>
</xsl:template>
<xsl:template match="vlak" mode="smer">
<div>
<xsl:attribute name="id"><xsl:value-of select="#smer" /></xsl:attribute>
</div>
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
Output will be HTML file, where items of the array will be div's id (div id="arrayItem"). Now the output is (that times and spaces aren't important now but some help I would welcome (link etc.)):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Rozpis vlaků pro stanici Podlešín</title>
</head>
<script type="text/javascript">
function show(element) {
var srcElement = document.getElementById(element);
if(srcElement != null) {
if(srcElement.style.display == "block") {
srcElement.style.display= 'none';
} else {
srcElement.style.display='block';
}
return false;
}
}
</script><body>
<h1>Stanice Podlešín</h1>
<div id=""></div>
16:20:00
<div id="Zloněves"></div>
17:00:00
<div id="Zloněves"></div>
16:18:00
16:23:00
<div id="Slaný předměstí"></div>
Nechranice
14:27:00
14:28:00
</body>
</html>
and I want this:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Rozpis vlaků pro stanici Podlešín</title>
</head>
<script type="text/javascript">
function show(element) {
var srcElement = document.getElementById(element);
if(srcElement != null) {
if(srcElement.style.display == "block") {
srcElement.style.display= 'none';
} else {
srcElement.style.display='block';
}
return false;
}
}
</script><body>
<h1>Stanice Podlešín</h1>
<div id="Zloněves"></div>
<div id="Slaný předměstí"></div>
</body>
</html>
Into those divs I will add more data and that ids I need for hiding divs with Javascript function show(id). And all elements which have smer="Zloněves" will be in one <div id="Zloněves"> and all elements which have smer="Slaný předměstí" will be in another one <div id="Slaný předměstí">
I have found some questions how to make an array but nothning solving this problem. Thanks for help.

This is a grouping problem, and in XSLT 1.0 you need to use a technique called Muenchain grouping.
You are grouping vlak elements by their smer attribute, so you define a key like so:
<xsl:key name="vlak" match="vlak[#smer]" use="#smer" />
So, for a given value, the key will return all vlak elements whose #smer attribute equals that value.
Now, to get the distinct elements, you need to match the vlak elements who occur first in the key for their given #smer value. This is done like so:
<xsl:template match="vlak[generate-id() = generate-id(key('vlak', #smer)[1])]" mode="smer">
And then within this template, should you so wish, to get all the vlak elements with this group, just access the key
<xsl:for-each select="key('vlak', #smer)">
The only other thing you would need is a template to match the other vlak elements to stop them being output outside this loop
<xsl:template match="vlak" mode="smer" />
Here is the full XSLT (I've removed the javascript for brevity)
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" />
<xsl:key name="vlak" match="vlak[#smer]" use="#smer" />
<xsl:template match="/">
<html>
<head>
<title>Rozpis vlaků pro stanici <xsl:value-of select="nadrazi/#jmeno" /></title>
</head>
<body>
<h1>Stanice <xsl:value-of select="nadrazi/#jmeno" /></h1>
<xsl:apply-templates select="nadrazi" mode="smer" />
</body>
</html>
</xsl:template>
<xsl:template match="vlak[generate-id() = generate-id(key('vlak', #smer)[1])]" mode="smer">
<div>
<xsl:attribute name="id"><xsl:value-of select="#smer" /></xsl:attribute>
<xsl:for-each select="key('vlak', #smer)">
<xsl:value-of select="odjezd" />
</xsl:for-each>
</div>
</xsl:template>
<xsl:template match="vlak" mode="smer" />
</xsl:stylesheet>
When applied to your XML, the following is output
<html>
<head>
<META http-equiv="Content-Type" content="text/html">
<title>Rozpis vlaků pro stanici Podlešín</title>
</head>
<body>
<h1>Stanice Podlešín</h1>
<div id="Zloněves">17:00:00 16:23:00</div>
<div id="Slaný předměstí">14:28:00</div>
</body>
</html>

HiHere i'm not giving the full code just giving the sample of fetching values
<xsl:for-each select="nadrazi/vlak">
<xsl:if test="#smer='Zloneves'">
<div id =<xsl:value-of select="#smer"/>>
<xsl:value-of select="prijezd"/>
<xsl:value-of select="odjezd"/>
</div>
</xsl:if>
</xsl:for-each>
In the above example i've used the <xsl:if> element <xsl:choose>
The sample ouput for the above code will be
<div id=Zloněves></div>
17:00:00
<div id=Zloněves></div>
16:18:00
16:23:00

Related

how to add logo in heading of extent report 2.41.2 selenium

I want to add image in my extent report. I tried with the below code in my XML.
<?xml version="1.0" encoding="UTF-8"?>
<suite name="MYhoenixTestExecution" verbose="1" >
<!-- <listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners> -->
<listeners>
<listener class-name="phoenix.report.ExtentReporterNG" />
</listeners>
<reportHeadline>Automation Report <image id="image-zoom">
<![CDATA[
<img src='C:\CATS\logo.png'/>
]]>
</image></reportHeadline>
<image id="image-zoom">
<![CDATA[
<img src='C:\CATS\logo.png'/>
]]>
</image>
<test name="Myphoenix_Login TC" >
<classes>
<class name="phoenix.testcases.Login_TC"/>
</classes>
</test>
But still unable to add logo. Please suggest.
I have successfully done that with ver3.1.2
This is my extent-config.xml below:
<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
<configuration>
<!-- report theme -->
<!-- standard, dark -->
<theme>dark</theme>
<!-- document encoding -->
<!-- defaults to UTF-8 -->
<encoding>UTF-8</encoding>
<!-- protocol for script and stylesheets -->
<!-- defaults to https -->
<protocol>https</protocol>
<!-- title of the document -->
<documentTitle>TRAX</documentTitle>
<!-- report name - displayed at top-nav -->
<reportName>
<![CDATA[
<img src='.//myCompanyLogo.svg' />
]]>
</reportName>
<!-- location of charts in the test view -->
<!-- top, bottom -->
<testViewChartLocation>bottom</testViewChartLocation>
<!-- custom javascript -->
<scripts>
<![CDATA[
$(document).ready(function() {
});
]]>
</scripts>
<!-- custom styles -->
<styles>
<![CDATA[
.report-name { padding-left: 10px; } .report-name > img { float:
left;height: 90%;margin-left: 30px;margin-top: 2px;width: auto; }
]]>
</styles>
</configuration>
</extentreports>
Please note that you have to take care of the location of the image. I have put the company logo in the Logo folder and copy it in the Reports folder before populating the html.report.

Why I cannot use a checkbox and radiobutton column using filterhead?

I have the next problem, when I use only two columns (one for the names and other for the checkbox or one for the names and other for the radiobutton) everything is fine, but when I use three columns(one for the names, other for the checkbox and the last for the radiobutton) I´ve got the next error in console when I try to write in the filter field.
filterheader.js:46 Uncaught TypeError: field.getValue is not a function
at g.<anonymous> (filterheader.js:46)
at Object.each (ext-all.js:19)
at g.runFiltering (filterheader.js:46)
at g.onFieldChange (filterheader.js:45)
at ext-all.js:19
I dont know what to do, I dont have much practice in ext.net. Before
an apology for my English. I would really appreciate some help.
<ext:GridPanel ID="grdNames" runat="server" Title="Names" HideCollapseTool="false" UI="Primary" HideHeaders="false" Layout="FitLayout" ColumnLines="false" BodyStyle="GridFiltros" Border="false" Region="Center" Frame="false" ForceFit="true" AutoScroll="false" Resizable="false">
<Store>
<ext:Store ID="strOrigen" runat="server">
<Model>
<ext:Model ID="Model25" runat="server">
<Fields>
<ext:ModelField Name="CheckNames" Type="Boolean" DefaultValue="false" />
<ext:ModelField Name="Names" />
</Fields>
</ext:Model>
</Store>
<View>
<ext:GridView ID="GridView6" runat="server" TrackOver="true" StripeRows="true" />
</View>
<ColumnModel ID="ColumnModel15" runat="server">
<Columns>
<ext:ComponentColumn ID="radColumn" runat="server" Width="30" DataIndex="CheckNames" Align="Left">
<Component>
<ext:Radio ID="rdGo" runat="server" Name="vGO">
</ext:Radio>
</Component>
</ext:ComponentColumn>
<ext:CheckColumn ID="CheckColumn" runat="server" DataIndex="CheckNames" Sortable="false" HideTitleEl="true" Width="35"
Resizable="false" StopSelection="false" Editable="true" Filterable="false" Align="Left"
Groupable="false" MenuDisabled="true">
<Items>
<ext:Checkbox runat="server" ID="chkRptGeoO" Checked="false">
<Listeners>
<Change Fn="chkChangeRptGeoO"></Change>
</Listeners>
</ext:Checkbox>
</Items>
</ext:CheckColumn>
<ext:Column ID="NamesColumn" runat="server" HideTitleEl="true" DataIndex="Names" MenuDisabled="true" Width="200" TabMenuHidden="true" />
</Columns>
</ColumnModel>
<Plugins>
<ext:FilterHeader ID="grdNames" runat="server" OnCreateFilterableField="OnCreateFilterableField">
</ext:FilterHeader>
</Plugins>
</ext:GridPanel>
I tried to reproduce your code but couldn't reproduce the issue. Maybe you need to upgrade your Ext.NET version?
Check if this works on your side, I tried reproducing your scenario with the code snippet you provided, but maybe I skipped something?
<%# Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
strOrigen.Data = new List<object>()
{
new { CheckNames = false, Names = "Name 1" },
new { CheckNames = false, Names = "Name 2" },
new { CheckNames = true, Names = "Name 3" },
new { CheckNames = false, Names = "Name 4" }
};
strOrigen.DataBind();
}
}
</script>
<html>
<head runat="server">
<title></title>
</head>
<body>
<form runat="server" id="fm1">
<div>
<ext:ResourceManager runat="server" />
<ext:GridPanel ID="grdNames" runat="server" Title="Names">
<Store>
<ext:Store ID="strOrigen" runat="server">
<Model>
<ext:Model ID="Model25" runat="server">
<Fields>
<ext:ModelField Name="CheckNames" Type="Boolean" DefaultValue="false" />
<ext:ModelField Name="Names" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<View>
<ext:GridView ID="GridView6" runat="server" TrackOver="true" StripeRows="true" />
</View>
<ColumnModel ID="ColumnModel15" runat="server">
<Columns>
<ext:ComponentColumn ID="radColumn" Text="radCol" runat="server" Width="30" DataIndex="CheckNames">
<Component>
<ext:Radio ID="rdGo" runat="server" Name="vGO">
</ext:Radio>
</Component>
</ext:ComponentColumn>
<ext:CheckColumn ID="CheckColumn" runat="server" Text="chkCol" Editable="false" Filterable="false" DataIndex="CheckNames" Width="35" MenuDisabled="true">
<Items>
<ext:Checkbox runat="server" ID="chkRptGeoO" Checked="false">
</ext:Checkbox>
</Items>
</ext:CheckColumn>
<ext:Column ID="NamesColumn" runat="server" Text="names" DataIndex="Names" Width="200" />
</Columns>
</ColumnModel>
<Plugins>
<ext:FilterHeader ID="FilterHeader1" runat="server">
</ext:FilterHeader>
</Plugins>
</ext:GridPanel>
</div>
</form>
</body>
</html>
Using Ext.NET 4.2.1 here.

Replace XML Span Element with Inner text of Span Tag in SQL Server

Replace span Element with its inner text whose class is "TAGGED_ITEM " in multiple rows with a column of type XML
<Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2">
<ItemBody>
<div class="item_text">
<div>
<span class="TAGGED_ITEM " id="c1_ae1">This is a map on a grid.</span>
<span class="TAGGED_ITEM " id="c1_ae2"> It shows a car.</span>
</div>
<span class="TAGGED_ITEM " id="c1_ae3"> It shows a car on Road.</span>
</div>
</ItemBody>
</Item>
Once Element is updated it should looks as below.
<Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2">
<ItemBody>
<div class="item_text">
<div>
This is a map on a grid.
It shows a car.
</div>
It shows a car on Road.
</div>
</ItemBody>
</Item>
This question had a particular namespace problem which, probably, had aroused the question. Eliminating namespaces on the match= does solve the problem. So an identity transform and a namespace-neutral matching gives the desired result:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[local-name() = 'span']">
<xsl:value-of select="text()" />
</xsl:template>
</xsl:stylesheet>
Result:
<?xml version="1.0"?>
<Item xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2" title="1234">
<ItemBody>
<div class="item_text">
<div>
This is a map on a grid.
It shows a car.
</div>
</div>
</ItemBody>
</Item>

<f:viewAction> included into facelets template client does not work [duplicate]

I have made a lot of progress in converting my JSF applications to book-markable pages, but I am wondering if I am doing it the right way. One question is that is there a best-practice location for the f:metadata tags?
My typical Facelets client page looks like this:
<ui:composition template="./pattern.xhtml">
<ui:define name="content">
<f:metadata>
<f:viewParam name="userId" value="#{bean.userId}" />
<f:viewParam name="startRecord" value="#{bean.startRecord}" />
<f:viewParam name="pageSize" value="#{bean.pageSize}" />
<f:viewParam name="sort" value="#{bean.sort}" />
</f:metadata>
<h1>Data Table</h1>
etc
So the f:metadata and child f:viewParam tags are encountered in the body of my page. My pattern.xhtml template also has a section (named "header") that could put these tags in the header section. Should they be put there? Does it make a difference or am I set up for some side effect I haven't seen yet?
Technically, it doesn't matter where you declare the <f:metadata> in the view as long as it's in the top level view (so, when using templating, in the template client and thus not in the master template). When the view get built, the metadata is basically not part of the JSF component tree, but of the view root (which you can obtain on a per-view basis by ViewDeclarationLanguage#getViewMetadata()).
Most self-documenting would be to put the <f:metadata> in the top of the view, so that you can see any metadata at first glance without the need to scroll to halfway or bottom the view source code.
When using a plain page, just put it right before the <h:head>.
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<f:metadata>
<f:viewParam name="userId" value="#{bean.userId}" />
<f:viewParam name="startRecord" value="#{bean.startRecord}" />
<f:viewParam name="pageSize" value="#{bean.pageSize}" />
<f:viewParam name="sort" value="#{bean.sort}" />
</f:metadata>
<h:head>
...
</h:head>
<h:body>
...
</h:body>
</html>
When using templating, the recommended approach, as stated in the <f:metadata> tag documentation, would be to declare a separate <ui:insert name="metadata"> in the master template and let the client define the <f:metadata> in an <ui:define name="metadata">.
<ui:composition template="/WEB-INF/pattern.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<ui:define name="metadata">
<f:metadata>
<f:viewParam name="userId" value="#{bean.userId}" />
<f:viewParam name="startRecord" value="#{bean.startRecord}" />
<f:viewParam name="pageSize" value="#{bean.pageSize}" />
<f:viewParam name="sort" value="#{bean.sort}" />
</f:metadata>
</ui:define>
<ui:define name="content">
<h1>Data Table</h1>
...
</ui:define>
</ui:composition>

How to make NewsList from News package show news as list

I'am calling the NewsList (from the standard Composite.News package) from a template like this:
<f:function name="Composite.News.NewsList" xmlns:f="http://www.composite.net/ns/function/1.0">
<f:param name="ListOptions" value="Show date,Show teaser" />
<f:param name="PageSize" value="10" />
<f:param name="DateFormat" value="dddd, MMMM dd, yyyy" />
</f:function>
I can't make it to show the news as a list. It only shows the first newsitem in the detailsmode.
What does the below line in the NewsList function do?
How can I make the control show my news in a list and not the first (most recent) item?
I have talked to a more experienced Composite Developer and he couldn't either make the Composite.News.Newslist show news in a list.
UPDATE:
I can se that the OMNICORP site doesn't use the standard News package. What is the reason for that?
Omnicorp Demo Site has its own News module based on global data type "Omnicorp.Content.News" and XSLT function "Omnicorp.Content.News"
Composite.News package is different and based on page data folder named "Composite.News.NewsItem" and two XSLT functions: "Composite.News.NewsList" and "Composite.News.NewsTeasers". So to use this package you should follow the steps described here - http://docs.composite.net/Packages/CompositeNews: create a page with page type = "News page". Add news item to the News page data folder (under the page). On the Content tab, have the Composite.News.NewsList function, which will render News List with links to the details.
But can I make the NewsTeasers list all the news and set up paging as well?
Yes you can. You can modify the existent NewsTeaser function or create the new function. On the Function Call tab modify the "Composite.News.NewsItem.GetNewsItemXml" function call and specify next parameters "PageNumber" and "IncludePagingInfo" with next values:
<f:param name="PageNumber">
<f:function name="Composite.Web.Request.QueryStringIntegerValue">
<f:param name="ParameterName" value="Page" />
<f:param name="FallbackValue" value="1" />
</f:function>
</f:param>
<f:param name="IncludePagingInfo" value="True" />
On the function Template tab add template to display PagingInfo:
<xsl:param name="pagingInfo" select="/in:inputs/in:result[#name='GetNewsItemXml']/PagingInfo" />
...
<xsl:if test="$pagingInfo/#TotalPageCount > 1">
<div class="Paging">
<xsl:apply-templates select="$pagingInfo" />
</div>
</xsl:if>
...
<xsl:template match="PagingInfo">
<xsl:param name="page" select="1" />
<xsl:if test="$page < #TotalPageCount + 1">
<xsl:if test="$page = #CurrentPageNumber">
<span><xsl:value-of select="$page" /></span>
</xsl:if>
<xsl:if test="not($page = #CurrentPageNumber)">
<xsl:value-of select="$page" />
</xsl:if>
<xsl:apply-templates select=".">
<xsl:with-param name="page" select="$page+1" />
</xsl:apply-templates>
</xsl:if>
</xsl:template>
For more information how to add Paging to the XSLT read this article- http://docs.composite.net/XSLT/SortingAndPaging

Resources