Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-10-2009
Member
 
Join Date: Jul 2009
Posts: 77
Problem with xls: for-each

I have a small problem with xml and xsl. Starting in Dev, I have always tried to stay away but then I had no choice. I need to display a table of milestones (date + event), so I have my table with 2 columns "Event" and "Date". Nothing too difficult so far.

In fact my XML file is generated via a PHP function. The tags are inserted in the drive in code and content is provided by variables. It may not super clear, but my a priory .xml file has no problem (I indented myself after because it does not work if I did it in the PHP where I created my .xml):

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet href="sheet.xsl" type="text/xsl"?>
<sheethl>
    <date>01-10-2009</date>
    <title><![CDATA[XSL3 - Design and milestones]]></title>
    <resp>Blabla</resp>
    <desc><![CDATA[Establishment of design.
Testing the new code level milestones (self-generation lines).]]></desc>
    <changes><![CDATA[* change1
* change2
* change3]]></changes>
    <ww><![CDATA[* Who
* When]]></ww>
    <milestones>
        <jde>
            <jdate>28-09-09</jdate>
            <jevent><![CDATA[event 1]]></jevent>
        </jde>
        <jde>
            <jdate>29-09-09</jdate>
            <jevent><![CDATA[event 2]]></jevent>
        </jde>
        <jde>
            <jdate>30-09-09</jdate>
            <jevent><![CDATA[event 3]]></jevent>
        </jde>
    </milestones>
    <fm><![CDATA[* FM1
* FM2
* FM3]]></fm>
    <ep><![CDATA[* EP1
* EP2
* EP3]]></ep>
</sheethl>
Let the file .xsl:
I created a template with appropriate milestones (in doubt): Code:
Code:
<xsl:template name="milestones" match="//milestones"> 
        <xsl:for-each select="//jde"> 
            <tr>
                <td>
                    <xsl:value-of select="//jevent"/> 
                </td>
                <td>
                    <xsl:value-of select="//jdate"/> 
                </td>
            </tr>
        </xsl:for-each>
</xsl:template>
And here's the part of the file .xsl template where this individual is known and used:
Code:
<table id="milestones">
    <tr>
        <th>Event</th>
        <th>Date</th>
    </tr>
    <xsl:call-template name="milestones"/>
</table>
All this gives me:

Event Date

Event 1 28-09-09
Event 1 28-09-09
Event 1 28-09-09

Show me in places in lines 2 and 3: "event 2" and "event 3" and "29-09-09" and "30-09-09" column for "Date"

Do you have an idea?
Reply With Quote
  #2  
Old 06-10-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Problem with xls: for-each

must instead use current () to reference the current element in your loop:
Code:
<tr>
    <td>
        <xsl:value-of select="current()/jevent"/>
    </td>
    <td>
        <xsl:value-of select="current()/jdate"/>
    </td>
</tr>
Reply With Quote
  #3  
Old 06-10-2009
Member
 
Join Date: Nov 2005
Posts: 1,323
Re: Problem with xls: for-each

If you remove the // before jde, jevent and jdate it works any better?

@ Reegan

It serves little purpose. I'm almost over (I have not tested) you can also remove the // before jde. Good but in your case it changes little because you have a milestone, but otherwise it would make things weird.
Reply With Quote
  #4  
Old 06-10-2009
Member
 
Join Date: Jul 2009
Posts: 77
Re: Problem with xls: for-each

If I tried to remove the // before jde but nothing appears.
Reply With Quote
  #5  
Old 06-10-2009
Member
 
Join Date: Nov 2005
Posts: 1,323
Re: Problem with xls: for-each

Yes, I had not seen you call your template by its name, suddenly your match = "//milestones" it is useless

but it would be cleaner to do:

Code:
<xsl:for-each select="/sheethl/milestones">  (or "//milestones" if you really prefer) 
    <xsl:call-template name="milestones"/>
</xsl:for-each>
and
Code:
<xsl: template name="milestones"> 
<xsl: for -each select="jde"> 
... 
</ xsl: for-each> 
</ xsl: template>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem with xls: for-each"
Thread Thread Starter Forum Replies Last Post
Sony VGNCS3 laptop 15 inch screen problem...LCD or CHIP problem? Mick$Tyler Hardware Peripherals 5 31-10-2010 06:49 AM
Blackberry Tour Youtube problem/facebook and phone freezing problem Lohitaksha Portable Devices 6 27-07-2010 12:10 AM
hard disk problem, clicking sound and windows problem rajat_2589 Hardware Peripherals 1 16-06-2010 11:34 PM
Toshiba satellite L305D-S5893 shutdown problem or bios update problem Colter Portable Devices 4 10-04-2010 04:19 PM
Hyperlink Problem, Unable to Open, A security problem has occurred LaKisha MS Office Support 1 30-11-2004 11:57 AM


All times are GMT +5.5. The time now is 02:46 AM.