My XML has 100 AgentSales nodes I only want to show the first 10 so far I have
<xsl:for-each select="NewDataSet/AgentSales">
<tr>
<xsl:if test="(position() mod 2 = 1)">
<xsl:attribute name="bgcolor">#cccccc</xsl:attribute>
</xsl:if>
<td>
<span style="font:20px arial; font-weight:bold;">
<xsl:value-of select="AgentName"/>
</span>
</td>
<td>
<span style="font:20px arial; font-weight:bold;">
<xsl:value-of select="State"/>
</span>
</td>
<td>
<span style="font:20px arial; font-weight:bold;">
<xsl:value-of select="time"/>
</span>
</td>
</tr>
</xsl:for-each>
New to the site but when I use the code brackets not all of my code shows? at least not in the preview below.
Use:
<xsl:for-each select="NewDataSet/AgentSales[not(position() >10)]">
<!-- Process each node from the node-list -->
</xsl:for-each>
Even better:
<xsl:apply-templates select="NewDataSet/AgentSales[not(position() >10)]"/>
Try something like:
<xsl:for-each select="NewDataSet/AgentSales">
<xsl:if test="position() <= 10">
...
</xsl:if>
</xsl:for-each>
Related
I am trying to get the count using the for-each and counter variable but I am getting an incorrect values. Any help with this would be great.
XML
<ProjectFileManagers>
<ProjectFileManagers>
<ProjectFileManagerId>34</ProjectFileManagerId>
<ProjectId>39352</ProjectId>
<FileManagerId>11</FileManagerId>
</ProjectFileManagers>
<ProjectFileManagers>
<ProjectFileManagerId>35</ProjectFileManagerId>
<ProjectId>39352</ProjectId>
<FileManagerId>12</FileManagerId>
</ProjectFileManagers>
</ProjectFileManagers>
XSLT
<tr>
<td colspan="5">
<span class="title">
<xsl:text>Material Attached</xsl:text>
</span>
<br />
<xsl:variable name="materialCount" select="0"></xsl:variable>
<xsl:for-each select="ProjectFileManagers/ProjectFileManagers/ProjectFileManagerId">
<xsl:value-of select="$materialCount + 1"/>
</xsl:for-each>
<xsl:value-of select="$materialCount" disable-output-escaping="yes" />
</td>
</tr>
in stead of
<xsl:value-of select="$materialCount + 1"/>
use:
<xsl:value-of select="position()"/>
I have two loops and want to count the iteration of cases OK and NotOK and overall cases inside xslt file.
How I cold do so? If I want to know the sum of both iteration how could I write it?
my For loops are as:
<xsl:for-each select="test">
<xsl:variable name="LinkName" select="attribute::name"/>
<tr>
<th style="text-align:left;vertical-align:top;position:"><a name="{$LinkName}"><xsl:value-of select="$LinkName"/></a></th>
<xsl:for-each select="descendant::node()">
<xsl:choose>
<xsl:when test="attribute::state='NotOK'">
<tr>
<td bgcolor="red"><xsl:value-of select="description"/></td>
</tr>
</xsl:when>
<xsl:when test="attribute::state='OK'">
<tr>
<td bgcolor="lime"><xsl:value-of select="description"/></td>
</tr>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</tr>
</xsl:for-each>
Update:
<table>
<tr bgcolor="coral">
<th>Test cases</th>
<th>Info</th>
</tr>
<xsl:for-each select="test">
<xsl:variable name="Summation"/>
<xsl:variable name="LinkIt" select="#name"/>
<xsl:choose>
<xsl:when test="descendant::node()/#state='NotOK'">
<tr>
<td bgcolor="red"><xsl:value-of select="$LinkIt"/></td>
<td>
<xsl:value-of select="count(descendant::node()[#state='NotOK'])"/> of <xsl:value-of select="count(descendant::node()[#state='OK']) + count(descendant::node()[#state='NotOK'])"/>
</td>
</tr>
</xsl:when>
<xsl:when test="descendant::node()/attribute::state='OK'">
<tr>
<td bgcolor="lime"><xsl:value-of select="$LinkIt"/></td>
<td>
---
</td>
</tr>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</table>
for-each is not a loop. If you want to count all descendant nodes of the test elements then simply use <xsl:value-of select="count(test/descendant::node())"/>. You can also add predicates to XPath expressions, like count(test/descendant::node()[attribute::state='NotOK']).
Inside of a <xsl:for-each select="test"> the context node is a test element so any count expression should be relative to that e.g. count(descendant::node()[attribute::state='NotOK']).
I woud like to make some nested loops over my xml doc
Here is my xml
<evolutionlist>
<date id="22_05_2014">
<objet>
<identifier>1VD5-3452-8R5</identifier>
<link>Link1</link>
<title>EXCHANGE OF ELEMENTS</title>
</objet>
<objet>
<identifier>1V24-34A2-8C5</identifier>
<link>Link1</link>
<title>NEW ELEMENT</title>
</objet>
</date>
<date id="21_05_2014">
<identifier>1VV4-34A2-8C5</identifier>
<link>Link2</link>
<title>REPLACE</title>
</date>
</evolutionlist>
Ideally, I woudl like to display something like
22_05_2014
objet1 (with add infos)
objet2 (with add infos)
21_05_2014
objet3 (with add infos)
I made:
<xsl:for-each select="//date">
<xsl:value-of select="#id"/>
<xsl:for-each select="objet">
<tr>
<td>
<xsl:value-of select="identifier"/>
</td>
<td>
<xsl:value-of select="link"/>
</td>
<td>
<xsl:value-of select="title"/>
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
but I got
22_05_2014 21_05_2014
objet1
objet2
objet3
where did I go wrong ?
EDIT
I tried
<xsl:for-each select="./objet">
for the second loop but that did not work either
Shame on me !
I forgot to do this:
<tr>
<td>
<xsl:value-of select="./#id"/>
</td>
</tr>
You were right, Ian Roberts, by encouraging me do write the real code
I have 3 radio button selection choices, and if the user selects the option "Forward" there is an input field for them to enter an email address. How can I make that input field required if they select the forward radio button? I can't seem to find any good information on XSLT required fields. The code is below:
<table cellpadding="0" id="allCategoryCheckboxes" >
<tr id="categoryRows">
<xsl:for-each select="form/categories/all/category">
<xsl:sort data-type="number" order="ascending"
select="((value='Available') * 1) +
((value='Unavailable') * 2) +
((value='Forward') * 3)"/>
<td>
<input type="radio" name="catUid">
<xsl:attribute name="value"><xsl:value-of select="uid"/></xsl:attribute>
<xsl:if test="uid = ../../current//category/uid"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if>
</input>
<xsl:value-of select="value"/>
<xsl:if test="value = 'Forward'">
<xsl:text> to: </xsl:text>
<xsl:variable name="someEmailAddress">
<xsl:if test="/bedework/formElements/form/xproperties/node()[name()='X-FORWARDING-ADDRESS']">
<xsl:value-of select="/bedework/formElements/form/xproperties/node()[name()='X-FORWARDING-ADDRESS']/values/text"/>
</xsl:if>
</xsl:variable>
<input type="text" name="someEmailForwardingAddress" value="{$someEmailAddress}" id="someEmailForwardingAddress"/>
</xsl:if>
</td>
</xsl:for-each>
</tr>
</table>
How to check the integer value in XSL? I'm using version 1.0
This is what I've tried, but it's not working:
<xsl:variable name="ShowEmailEventId"
select="com.zoniac.emailevent.NewEmailEventBean/emailEventIdString"/>
<xsl:if test="$ShowEmailEventId !=48">
<table align="center"
width="96%"
border="1"
style="border-color:#2E73AD;border-collapse:collapse"
cellspacing="0"
cellpadding="10">
<tr>
<td width="10%"
style="border-color:#2E73AD;color: black; font: 11px verdana;padding:2px"
align="left"
valign="top">
<b>S.No</b>
</td>
</tr>
</table>
</xsl:if>
This is probably the shortest expression, returning true() iff $x can be used as an integer:
Just use:
floor($x) = $x
The full test will be:
<xsl:if test="floor($x) = $x">
<!-- $x is an integer -->
</xsl:if>
or
<xsl:when test="floor($x) = $x">
<!-- $x is an integer -->
</xsl:when>
or
someXPathExpression[floor($x) = $x]
TO check if a value nameofint is an int... (you are obviously going to want to change the inside of the if condition.
<xsl:template match="CheckInt">
<xsl:if test="not(string(.) castable as xs:integer)">
<xsl:text>NOT AN INT: </xsl:text>
<xsl:value-of select="."/>
</xsl:if>
</xsl:template>