xsl-list
[Top] [All Lists]

Re: [xsl] Create Table

2010-03-31 15:13:20
Hi all,

I wanted to sort of start over with this one.  I feel I am close, but the final 
solution is still evading me.  Anyway just wanted to re-submit my xml and xsl 
examples and ask some new questions.  I have to thank Eric and others for 
helping a newbie get this far. :)  All the solutions were great, the problem 
was that I didn't fully understand the challenges.  My fault!  Also, I am 
developing for the browser if that changes things.  

Anyway, I am trying to format xml from a Software Build System into an html 
table.  The goal is to create a table that takes 'general' data for each code 
change and place it in a table row.  This data comes from nodes with field 
attributes of 'file','version','date','user','CR Number', and 'comment'.  I 
have this working.  What I need to do next is fill a cell in the next row with 
all the nodes with a field attribute of 'diff', this could be two lines or 40.  
Basically, in the new row select all nodes with a diff that come after 
@field='comment', until the next time the attribute field does not equal diff 
or equals 'file'.  I also, will need to keep track of the attribute lineId 
because the data nodes are sorted in a really "unique" way (e.g. the first 
node's lineId is 61.  The xsl below gets close to what I want but selects more 
@field=diff nodes than I want.  

Also, with the recursive templates , I am having trouble with the test.  My 
context node has an attribute of file, but I want to recursively grab all the 
nodes for that change where attribute = diff.  

I apologize for the large xml segment, but I think it will help clarify the 
challenges. I have been experimenting a lot so the code may not be that clean.  

Thanks so much.  I am learning a lot here...

XML:

<interface-categories><categoryname="Source 
Changes"category="Source"><datalineId="61"section="diff"field="diff">266c267,273</data><datalineId="62"section="diff"field="diff">&lt;
 continue 
workerPayComponentLoop;</data><datalineId="63"section="diff"field="diff">---</data><datalineId="64"section="diff"field="diff">&gt;
 continue 
workerPayComponentLoop;</data><datalineId="65"section="diff"field="diff">&gt; } 
else {</data><datalineId="66"section="diff"field="diff">&gt; if 
(clientCategoryCode.equals("blank") &amp;&amp; 
"5".equals(row.getString("icpc_calc"))</data><datalineId="67"section="diff"field="diff">&gt;
 &amp;&amp; (waLIValues.contains(desc) &amp;&amp; 
!hasActiveWaPolicy(row.getLong("icpc_ic_id"))))</data><datalineId="68"section="diff"field="diff">&gt;
 {</data><datalineId="69"section="diff"field="diff">&gt; setMemoInd = 
true;</data><datalineId="70"section="diff"field="diff">&gt;
 
}</data><datalineId="71"section="diff"field="diff">509a517</data><datalineId="72"section="diff"field="diff">&gt;
 
{</data><datalineId="73"section="diff"field="diff">510a519,521</data><datalineId="74"section="diff"field="diff">&gt;
 if (setMemoInd)</data><datalineId="75"section="diff"field="diff">&gt; 
method.setIncludeMemoHours(true);</data><datalineId="76"section="diff"field="diff">&gt;
 
}</data><datalineId="77"section="diff"field="diff">777c788,796</data><datalineId="78"section="diff"field="diff">&lt;
 } 
</data><datalineId="79"section="diff"field="diff">---</data><datalineId="80"section="diff"field="diff">&gt;
 }</data><datalineId="81"section="diff"field="diff">&gt; 
</data><datalineId="82"section="diff"field="diff">&gt; private boolean 
hasWorkersCompProduct (Client clt) throws 
PayrollException</data><datalineId="83"section="diff"field="diff">&gt; 
{</data><datalineId="84"section="diff"field="diff">&gt; ClientProduct 
reportService =
 ConversionHelper.getClientProductByType(clt.getPrimaryKey(), 
ProductType.PAYCHEX_WORKERS__COMPENSATION_REPORT_SERVICE, 
clt.getAsOfDate());</data><datalineId="85"section="diff"field="diff">&gt; if 
(reportService != null)</data><datalineId="86"section="diff"field="diff">&gt; 
return true;</data><datalineId="87"section="diff"field="diff">&gt; return 
false;</data><datalineId="88"section="diff"field="diff">&gt; 
}</data><datalineId="89"section="Section1"field="URL">[url]\\rnd-spbuild-1\web\nightly\spr2010_apr_dev\CA_C-b3h_179_spr2010_apr_dev\index.html[/url]</data><datalineId="31"section="diff"field="diff">1012c1024</data><datalineId="32"section="diff"field="diff">&lt;
 setMethod(row.getString("icpc_calc"), row.getString("ic_401k_calc"), 
clientPayComponent);</data><datalineId="33"section="diff"field="diff">---</data><datalineId="34"section="diff"field="diff">&gt;
 setMethod(row.getString("icpc_calc"), row.getString("ic_401k_calc"), 
clientPayComponent,
 
setMemoInd);</data><datalineId="35"section="diff"field="diff">1125a1138,1145</data><datalineId="36"section="diff"field="diff">&gt;
 }</data><datalineId="37"section="diff"field="diff">&gt; 
</data><datalineId="38"section="diff"field="diff">&gt; private boolean 
hasWorkersCompProduct (Client clt) throws 
PayrollException</data><datalineId="39"section="diff"field="diff">&gt; 
{</data><datalineId="40"section="diff"field="diff">&gt; ClientProduct 
reportService = ConversionHelper.getClientProductByType(clt.getPrimaryKey(), 
ProductType.PAYCHEX_WORKERS__COMPENSATION_REPORT_SERVICE, 
clt.getAsOfDate());</data><datalineId="41"section="diff"field="diff">&gt; if 
(reportService != null)</data><datalineId="42"section="diff"field="diff">&gt; 
return true;</data><datalineId="43"section="diff"field="diff">&gt; return
 
false;</data><datalineId="44"section="changes"field="file">.\payx\domain\dev\src\com\paychex\spr\domain\conversion\task\ConvertHistoryWages.java</data><datalineId="45"section="changes"field="version">\main\spr2010_apr_dev\2</data><datalineId="46"section="changes"field="date">20100310.102844</data><datalineId="47"section="changes"field="user">jryan</data><datalineId="48"section="changes"field="cr_number">602018</data><datalineId="49"section="changes"field="comment">fix
 for log 
5960</data><datalineId="50"section="diff"field="diff">1296a1297,1298</data><datalineId="51"section="diff"field="diff">&gt;
 } else {</data><datalineId="52"section="diff"field="diff">&gt;
 
chkpc.setWorkerPaycomponentMemoHoursIndicator(true);</data><datalineId="53"section="changes"field="file">.\payx\domain\dev\src\com\paychex\spr\domain\conversion\task\CreateWorkerPayComponents.java</data><datalineId="54"section="changes"field="version">\main\spr2010_apr_dev\1</data><datalineId="55"section="changes"field="date">20100310.102819</data><datalineId="56"section="changes"field="user">jryan</data><datalineId="57"section="changes"field="cr_number">602018</data><datalineId="58"section="changes"field="comment">fix
 for log 
5960</data><datalineId="59"section="diff"field="diff">261a262</data><datalineId="60"section="diff"field="diff">&gt;
 boolean setMemoInd = 
false;</data><datalineId="3"section="changes"field="date">20100310.102809</data><datalineId="4"section="changes"field="user">jryan</data><datalineId="5"section="changes"field="cr_number">602018</data><datalineId="6"section="changes"field="comment">fix
 for log
 
5960</data><datalineId="7"section="diff"field="diff">18a19</data><datalineId="8"section="diff"field="diff">&gt;
 import 
com.paychex.spr.clientproduct.ClientProduct;</data><datalineId="9"section="diff"field="diff">19a21,22</data><datalineId="10"section="diff"field="diff">&gt;
 import 
com.paychex.spr.clientproduct.config.ProductFinderUtility;</data><datalineId="11"section="diff"field="diff">&gt;
 import 
com.paychex.spr.clientproduct.ejb.ClientProductAssembler;</data><datalineId="12"section="diff"field="diff">720c723</data><datalineId="13"section="diff"field="diff">&lt;
 private void setMethod(String code, String calc401k, ClientPayComp 
clientPayComponent)</data><datalineId="14"section="diff"field="diff">---</data><datalineId="15"section="diff"field="diff">&gt;
 private void setMethod(String code, String calc401k, ClientPayComp 
clientPayComponent, boolean
 
setMemoInd)</data><datalineId="16"section="diff"field="diff">731a735,736</data><datalineId="17"section="diff"field="diff">&gt;
 if (setMemoInd)</data><datalineId="18"section="diff"field="diff">&gt; 
method.setIncludeMemoHours(true);</data><datalineId="19"section="diff"field="diff">967a973</data><datalineId="20"section="diff"field="diff">&gt;
 boolean setMemoInd = 
false;</data><datalineId="21"section="diff"field="diff">972c978,984</data><datalineId="1"section="changes"field="file">.\payx\domain\dev\src\com\paychex\spr\domain\conversion\task\ConvertClientPayComponents.java</data><datalineId="2"section="changes"field="version">\main\spr2010_apr_dev\1</data><datalineId="22"section="diff"field="diff">&lt;
 continue 
clientPaycomponentLoop;</data><datalineId="23"section="diff"field="diff">---</data><datalineId="24"section="diff"field="diff">&gt;
 continue 
clientPaycomponentLoop;</data><datalineId="25"section="diff"field="diff">&gt; } 
else
 {</data><datalineId="26"section="diff"field="diff">&gt; if 
(categoryCode.equals("blank") &amp;&amp; 
"5".equals(row.getString("icpc_calc"))</data><datalineId="27"section="diff"field="diff">&gt;
 &amp;&amp; (waLIValues.contains(desc) &amp;&amp; 
!hasActiveWaPolicy(clientKey)))</data><datalineId="28"section="diff"field="diff">&gt;
 {</data><datalineId="29"section="diff"field="diff">&gt; setMemoInd = 
true;</data><datalineId="30"section="diff"field="diff">&gt; }</data></category>


XSL:  Partially working

<?xml version='1.0' 
encoding='utf-8'?><xsl:stylesheetversion='1.0'xmlns='http://www.w3.org/1999/xhtml'xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:outputomit-xml-declaration='no'method='xml'indent='yes'xml:space='default'encoding='utf-8'/><xsl:templatematch='/'><htmlxml:lang='en'><head><title>table
 example</title><!--<style 
type='text/css'>table{table-layout:fixed;width:auto}</style>--></head><body><tablewidth='0'summary='summary
 goes here for accessibility'border="1"><caption>Source 
Changes</caption><thead><tr><th>File</th><th>Version</th><th>Date</th><th>User</th><th>CR
 
Number</th><th>Comment</th></tr></thead><tbody><xsl:apply-templatesselect="//category[(_at_)name='Source
 
Changes']/data[(_at_)field='file']"/></tbody></table></body></html></xsl:template><xsl:templatematch='data'><xsl:paramname='i'select='./@lineId'></xsl:param><!--***can't
 use following-sibling here because some are not following need to find based on
 
lineId***--><tr><th><xsl:value-ofselect='.'/></th><th><xsl:value-ofselect='//data[(_at_)lineId
 = $i+1]'/></th><th><xsl:value-ofselect='//data[(_at_)lineId = 
$i+2]'/></th><th><xsl:value-ofselect='//data[(_at_)lineId = 
$i+3]'/></th><th><xsl:value-ofselect='//data[(_at_)lineId = 
$i+4]'/></th><th><xsl:value-ofselect='//data[(_at_)lineId = 
$i+5]'/></th></tr><tr><td><xsl:call-templatename="diffs"><xsl:with-paramname="lineNumber"select="./@lineId
 
+6"/><xsl:with-paramname="field"select="@field"/></xsl:call-template></td></tr></xsl:template><xsl:templatename="diffs"><xsl:paramname="lineNumber"/><xsl:iftest="($lineNumber!=80)"><!--***This
 was just to get something to show up, I need help 
here****--><xsl:value-ofselect='following::data[(_at_)field="diff" and 
@lineId=$lineNumber]'/><xsl:call-templatename="diffs"><xsl:with-paramname="lineNumber"select="$lineNumber
 + 1"/></xsl:call-template></xsl:if></</xsl:template>xsl:stylesheet>



----- Original Message ----
From: bernie bonn <moochambo(_at_)yahoo(_dot_)com>
To: Eric J. Bowman <eric(_at_)bisonsystems(_dot_)net>; 
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Sent: Tue, March 30, 2010 3:31:45 PM
Subject: Re: [xsl] Create Table

HI Eric,  as always thanks for your help!

I am getting so close.  What you gave me didn't completely solve the problem, 
but it helped me to think what the context is, and I did some more research to 
get the table looking like I wanted.  (Not sure if it is the best way to do it, 
but I can worry about that later).  

So I have my table built with all the source changes, now I want to add a row 
with the 'diffs' for each change(could be 30 or more nodes).  The challenge is 
after i have grabbed  the the File, version, date etc for the first row,  I 
need to then somehow grab all the data nodes where @field=diff, until the next 
node where @field!=diff, and place it in the next row.  Off topic, I plan on 
using JavaScript to hide the diff detail unless use wants to see it.  Seems 
like a while loop, but I know those don't exist.  I also am currently 
experimenting with named templates, although struggling with how to set 
context.  

Sorry this is so muddled, let me know if you need clarifications.  
Thanks again,

Bernie



----- Original Message ----
From: Eric J. Bowman <eric(_at_)bisonsystems(_dot_)net>
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Cc: bernie bonn <moochambo(_at_)yahoo(_dot_)com>
Sent: Sat, March 27, 2010 3:22:26 AM
Subject: Re: [xsl] Create Table


So this answer extends the example already given, by adding the number
() function.


Heh, don't listen to me, I'm still learning myself... number() isn't 
needed here, as this works just fine:

<th><xsl:value-of select='./@lineId+1'/></th>

What I've just learned, is that I need to take a closer look at how
XSLT processors handle typing, my answer assumed number() was needed in
order to perform addition like you were trying, and was thus totally 
wrong.

Anyway, I played around with it a bit more, adding this to my <tr>
template:

<xsl:param name='x' select='./@lineId'/>

And changing the <th> two different ways, as follows:

<th><xsl:value-of 
select='following-sibling::data[(_at_)lineId=$x]/@lineId'/></th>
<th><xsl:value-of 
select='following-sibling::data[(_at_)lineId=$x+1]/@lineId'/></th>

The first line results in <th/>, the second line works as expected.
The first line can be rewritten as select='//data[(_at_)lineId=$x]/@lineId' 
and it will work as expected.  So I suspect your problem is one of not
minding your context node, i.e. you started with this:

<xsl:param name='x' select='./@lineId'/>

Then, you have <xsl:value-of select='data[(_at_)lineId=$x]'/>, which can't 
work  because you haven't selected an axis...  So it's hard to know how 
to specifically help you here -- the 'data[(_at_)lineId=$x]' is correct, but 
only if it's preceded by a proper axis, and followed by '/@lineId' since 
you're after attribute content, instead of element content.

-Eric


      

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>