Subject: Re: [xsl] Create Table From: bernie bonn <moochambo@xxxxxxxxx> Date: Wed, 31 Mar 2010 13:12:41 -0700 (PDT) |
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">< continue workerPayComponentLoop;</data><datalineId="63"section="diff"field="diff">---< /data><datalineId="64"section="diff"field="diff">> continue workerPayComponentLoop;</data><datalineId="65"section="diff"field="diff">> } else {</data><datalineId="66"section="diff"field="diff">> if (clientCategoryCode.equals("blank") && "5".equals(row.getString("icpc_calc"))</data><datalineId="67"section="diff"fi eld="diff">> && (waLIValues.contains(desc) && !hasActiveWaPolicy(row.getLong("icpc_ic_id"))))</data><datalineId="68"section ="diff"field="diff">> {</data><datalineId="69"section="diff"field="diff">> setMemoInd = true;</data><datalineId="70"section="diff"field="diff">> }</data><datalineId="71"section="diff"field="diff">509a517</data><datalineId ="72"section="diff"field="diff">> {</data><datalineId="73"section="diff"field="diff">510a519,521</data><datalin eId="74"section="diff"field="diff">> if (setMemoInd)</data><datalineId="75"section="diff"field="diff">> method.setIncludeMemoHours(true);</data><datalineId="76"section="diff"field=" diff">> }</data><datalineId="77"section="diff"field="diff">777c788,796</data><datalin eId="78"section="diff"field="diff">< } </data><datalineId="79"section="diff"field="diff">---</data><datalineId="80"s ection="diff"field="diff">> }</data><datalineId="81"section="diff"field="diff">> </data><datalineId="82"section="diff"field="diff">> private boolean hasWorkersCompProduct (Client clt) throws PayrollException</data><datalineId="83"section="diff"field="diff">> {</data><datalineId="84"section="diff"field="diff">> ClientProduct reportService = ConversionHelper.getClientProductByType(clt.getPrimaryKey(), ProductType.PAYCHEX_WORKERS__COMPENSATION_REPORT_SERVICE, clt.getAsOfDate());</data><datalineId="85"section="diff"field="diff">> if (reportService != null)</data><datalineId="86"section="diff"field="diff">> return true;</data><datalineId="87"section="diff"field="diff">> return false;</data><datalineId="88"section="diff"field="diff">> }</data><datalineId="89"section="Section1"field="URL">[url]\\rnd-spbuild-1\we b\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"s ection="diff"field="diff">< setMethod(row.getString("icpc_calc"), row.getString("ic_401k_calc"), clientPayComponent);</data><datalineId="33"section="diff"field="diff">---</da ta><datalineId="34"section="diff"field="diff">> 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">> }</data><datalineId="37"section="diff"field="diff">> </data><datalineId="38"section="diff"field="diff">> private boolean hasWorkersCompProduct (Client clt) throws PayrollException</data><datalineId="39"section="diff"field="diff">> {</data><datalineId="40"section="diff"field="diff">> ClientProduct reportService = ConversionHelper.getClientProductByType(clt.getPrimaryKey(), ProductType.PAYCHEX_WORKERS__COMPENSATION_REPORT_SERVICE, clt.getAsOfDate());</data><datalineId="41"section="diff"field="diff">> if (reportService != null)</data><datalineId="42"section="diff"field="diff">> return true;</data><datalineId="43"section="diff"field="diff">> return false;</data><datalineId="44"section="changes"field="file">.\payx\domain\dev \src\com\paychex\spr\domain\conversion\task\ConvertHistoryWages.java</data><d atalineId="45"section="changes"field="version">\main\spr2010_apr_dev\2</data> <datalineId="46"section="changes"field="date">20100310.102844</data><dataline Id="47"section="changes"field="user">jryan</data><datalineId="48"section="cha nges"field="cr_number">602018</data><datalineId="49"section="changes"field="c omment">fix for log 5960</data><datalineId="50"section="diff"field="diff">1296a1297,1298</data><d atalineId="51"section="diff"field="diff">> } else {</data><datalineId="52"section="diff"field="diff">> chkpc.setWorkerPaycomponentMemoHoursIndicator(true);</data><datalineId="53"s ection="changes"field="file">.\payx\domain\dev\src\com\paychex\spr\domain\con version\task\CreateWorkerPayComponents.java</data><datalineId="54"section="ch anges"field="version">\main\spr2010_apr_dev\1</data><datalineId="55"section=" changes"field="date">20100310.102819</data><datalineId="56"section="changes"f ield="user">jryan</data><datalineId="57"section="changes"field="cr_number">60 2018</data><datalineId="58"section="changes"field="comment">fix for log 5960</data><datalineId="59"section="diff"field="diff">261a262</data><dataline Id="60"section="diff"field="diff">> boolean setMemoInd = false;</data><datalineId="3"section="changes"field="date">20100310.102809</da ta><datalineId="4"section="changes"field="user">jryan</data><datalineId="5"se ction="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">> import com.paychex.spr.clientproduct.ClientProduct;</data><datalineId="9"section="di ff"field="diff">19a21,22</data><datalineId="10"section="diff"field="diff">> import com.paychex.spr.clientproduct.config.ProductFinderUtility;</data><datalineId= "11"section="diff"field="diff">> import com.paychex.spr.clientproduct.ejb.ClientProductAssembler;</data><datalineId=" 12"section="diff"field="diff">720c723</data><datalineId="13"section="diff"fie ld="diff">< private void setMethod(String code, String calc401k, ClientPayComp clientPayComponent)</data><datalineId="14"section="diff"field="diff">---</dat a><datalineId="15"section="diff"field="diff">> private void setMethod(String code, String calc401k, ClientPayComp clientPayComponent, boolean setMemoInd)</data><datalineId="16"section="diff"field="diff">731a735,736</da ta><datalineId="17"section="diff"field="diff">> if (setMemoInd)</data><datalineId="18"section="diff"field="diff">> method.setIncludeMemoHours(true);</data><datalineId="19"section="diff"field=" diff">967a973</data><datalineId="20"section="diff"field="diff">> boolean setMemoInd = false;</data><datalineId="21"section="diff"field="diff">972c978,984</data><da talineId="1"section="changes"field="file">.\payx\domain\dev\src\com\paychex\s pr\domain\conversion\task\ConvertClientPayComponents.java</data><datalineId=" 2"section="changes"field="version">\main\spr2010_apr_dev\1</data><datalineId= "22"section="diff"field="diff">< continue clientPaycomponentLoop;</data><datalineId="23"section="diff"field="diff">---< /data><datalineId="24"section="diff"field="diff">> continue clientPaycomponentLoop;</data><datalineId="25"section="diff"field="diff">> } else {</data><datalineId="26"section="diff"field="diff">> if (categoryCode.equals("blank") && "5".equals(row.getString("icpc_calc"))</data><datalineId="27"section="diff"fi eld="diff">> && (waLIValues.contains(desc) && !hasActiveWaPolicy(clientKey)))</data><datalineId="28"section="diff"field="di ff">> {</data><datalineId="29"section="diff"field="diff">> setMemoInd = true;</data><datalineId="30"section="diff"field="diff">> }</data></category> XSL: Partially working <?xml version='1.0' encoding='utf-8'?><xsl:stylesheetversion='1.0'xmlns='http://www.w3.org/1999/x html'xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:outputomit-xml-dec laration='no'method='xml'indent='yes'xml:space='default'encoding='utf-8'/><xs l: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>Use r</th><th>CR Number</th><th>Comment</th></tr></thead><tbody><xsl:apply-templatesselect="// category[@name='Source Changes']/data[@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[@lineId = $i+1]'/></th><th><xsl:value-ofselect='//data[@lineId = $i+2]'/></th><th><xsl:value-ofselect='//data[@lineId = $i+3]'/></th><th><xsl:value-ofselect='//data[@lineId = $i+4]'/></th><th><xsl:value-ofselect='//data[@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></t r></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[@field="diff" and @lineId=$lineNumber]'/><xsl:call-templatename="diffs"><xsl:with-paramname="li neNumber"select="$lineNumber + 1"/></xsl:call-template></xsl:if></</xsl:template>xsl:stylesheet> ----- Original Message ---- From: bernie bonn <moochambo@xxxxxxxxx> To: Eric J. Bowman <eric@xxxxxxxxxxxxxxxx>; xsl-list@xxxxxxxxxxxxxxxxxxxxxx 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@xxxxxxxxxxxxxxxx> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Cc: bernie bonn <moochambo@xxxxxxxxx> 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[@lineId=$x]/@lineId'/></th> <th><xsl:value-of select='following-sibling::data[@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[@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[@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[@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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Create Table, Wolfgang Laun | Thread | [xsl] CDATA to XML - work with tran, [x] cross solution |
[xsl] Balisage Student Support Awar, B Tommie Usdin | Date | |
Month |