Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 30th, 2007, 01:22 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT Table Row with repetitive first cell

hi, i'm using saxon 8.8, xslt 2.0, html output, UTF-8.

i have a really simply question that i'm going to kick myself over once answered:

XML Sample:

Code:
<EICAS>
  <EICAS_TITLE>A-I WING 1(2) LEAK</EICAS_TITLE>
  <COMPONENT>Wing Anti-Ice System</COMPONENT>
  <COMPONENT>Wing Anti-Ice Valves</COMPONENT>
  <DISP_COND mel_ref="30-11-00"/>
  <DISP_COND mel_ref="30-11-01"/>
  <REMARK>
    -
  </REMARK>
  <REMARK>
    -
  </REMARK>
</EICAS>
<EICAS>
  <EICAS_TITLE>CABIN ALTITUDE HI</EICAS_TITLE>
  <COMPONENT>CPCS Controller</COMPONENT>
  <COMPONENT>Outflow Valve</COMPONENT>
  <DISP_COND mel_ref="21-31-01"/>
  <DISP_COND mel_ref="21-31-02"/>
  <REMARK>
    -
  </REMARK>
  <REMARK>
    -
  </REMARK>
</EICAS>
i need a template to put each repeated element in a new row with the EICAS_TITLE element repeated in the first cell. each element position corresponds to the other elements in that position, so <component>[2] is same row as <disp_cond>[2]:

Code:
<eicas>
 __________________________________________________
|              |            |            |         |
|<eicas_title1>|<component1>|<disp_cond1>|<remark1>|
|______________|____________|____________|_________|
|              |            |            |         |
|<eicas_title1>|<component2>|<disp_cond2>|<remark2>|
|______________|____________|____________|_________| 

</eicas>
originally i have one row per <eicas>, with multiple occurring child elements repeating within a border seperated cell, but i'm writing multiple resulting-documents each with specific groupings and now need each child element in its own row while maintaining its association to the <eicas_title> element.

i know, it's simple. i'm learning so much that i forget the easy stuff.
 
Old May 30th, 2007, 02:08 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm not sure I've really understood the requirement, but I think I would write this as

<xsl:template match="EICAS">
  <eicas>
  <tr>
    <xsl:for-each select="EICAS_TITLE, COMPONENT[1], DISP_COND[1], REMARK[1]">
       <td><xsl:value-of select="."/></td>
    </xsl:for-each>
  </tr>
  <tr>
    <xsl:for-each select="EICAS_TITLE, COMPONENT[2], DISP_COND[2], REMARK[2]">
       <td><xsl:value-of select="."/></td>
    </xsl:for-each>
  </tr>



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 30th, 2007, 04:07 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

spot on, and you're right; i didn't explain the requirement thoroughly.

basically, <eicas_title> only appears once. however, the remaining three child nodes are unbounded. (i used two in my example for brevity's sake, sorry.) this means i need a variable number of rows to spawn.

one key point is that, in one <eicas> parent, if there are <component>[n] there will always be <disp_cond> and <remark> [n] with the same <eicas_title>[1].

i know it would have made more sense to make <comp>, <disp> and <remark> children of <eicas_title>, but like i said, i'm producing an output variation based on a grouping that wasn't forseen.

the grouping encompasses @mel_ref within <disp_cond mel_ref="21-31-01"/>.

there's no point in grouping by substring-before(@mel_ref, '-') when i have "21-31-01" and "52-01-02" etc. in the same cell.

right now, <tr> look like this:

Code:
<eicas>
 ________________________________________________
|            | component 1 | 21-31-01 | remark 1 |  
| eicas title| component 2 | 52-01-02 | remark 2 |
|            | component n | nn-nn-nn | remark n |
|____________|____etc______|____etc___|___etc____|
</eicas>
each line of <component>, <disp>_cond (21-31-01) and <remark> are seperated by a gray border to show their data relationships.

i need to turn each one of those varying number of lines into a new <tr> with the same <eicas_title> in the first cell, so that i can group and sort by the first two \d in <disp_cond> (see example in first post).

i would post my attempted code, but i am ashamed to say, it just evades me.

what you posted was amazing considering my requirements were vague.

thanks so much.
 
Old May 30th, 2007, 04:27 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Perhaps you need

<xsl:variable name="EICAS" select="."/>
<xsl:for-each select="1 to count(component)">
   <xsl:variable name="p" select="."/>
   <tr>
     <td><xsl:value-of select="$EICAS/EICAS_TITLE"></td>
     <td><xsl:value-of select="$EICAS/COMPONENT[$p]"></td>
     <td><xsl:value-of select="$EICAS/DISP_COND[$p]"></td>
     <td><xsl:value-of select="$EICAS/REMARK[$p]"></td>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 1st, 2007, 12:46 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you, sir. it does what it should. i still need to tweak it though.

i failed to mention that <disp_cond> can also contain other @ values i'll have to filter since all i want are <disp_cond> with @mel_ref.

it also seems that each eicas instance is repeating, so it breaks the lines up perfectly, but now i'm getting two of each.

thanks again. i'm glad you're here helping us along. i'll keep at it.
 
Old July 3rd, 2007, 01:29 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, it's difficult for me to capture all data variances in a drummed down version. the file is very large.

i really appreciate your help. i actually found a solution the day after our last posts. i've had several other urgent projects that have kept me away, but in the interest of closure, here's my solution.

Code:
<xsl:for-each select="//DISP_COND">
 <xsl:sort select="@mel_ref"/>
 <xsl:for-each select="@mel_ref">
  <xsl:variable name="disp" select="../../count(DISP_COND)"/>
  <tr>
   <td>
    <xsl:apply-templates select=".."/>
    <td>
     <xsl:apply-templates select="../../COMPONENT[position()=$disp -../count(preceding-sibling::DISP_COND)]"/>
    </td>
    <td>
     <xsl:apply-templates select="../../EICAS_TITLE"/>
    </td>
    <td>
     <xsl:apply-templates select="../../REMARK[position()=$disp -../count(preceding-sibling::DISP_COND)]"/>
    </td>
   </td>
 </tr>
 </xsl:for-each>
</xsl:for-each>
thanks again!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
restrict entry to only one cell in a row sriramus Access VBA 1 March 3rd, 2006 02:14 PM
UPDATING 1 row with another row in same table rit01 SQL Server 2000 3 February 19th, 2006 08:55 AM
Parsing and Removing CSV values in row cell. peryan77 SQL Server 2000 5 February 2nd, 2006 03:48 PM
Row Color depending on if cell value same as prev case23_69 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 February 17th, 2005 01:37 PM
insert new row and merge with existing merged cell funkyProgrammer Excel VBA 1 February 9th, 2004 10:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.