Results 1 to 5 of 5

Thread: Problem with xls: for-each

  1. #1
    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?

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    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>

  3. #3
    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.

  4. #4
    Join Date
    Jul 2009
    Posts
    77

    Re: Problem with xls: for-each

    If I tried to remove the // before jde but nothing appears.

  5. #5
    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>

Similar Threads

  1. Sony VGNCS3 laptop 15 inch screen problem...LCD or CHIP problem?
    By Mick$Tyler in forum Hardware Peripherals
    Replies: 5
    Last Post: 31-10-2010, 06:49 AM
  2. Replies: 6
    Last Post: 27-07-2010, 12:10 AM
  3. hard disk problem, clicking sound and windows problem
    By rajat_2589 in forum Hardware Peripherals
    Replies: 1
    Last Post: 16-06-2010, 11:34 PM
  4. Replies: 4
    Last Post: 10-04-2010, 04:19 PM
  5. Replies: 1
    Last Post: 30-11-2004, 11:57 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,034,672.24413 seconds with 16 queries