XSL setting flag variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sidathkp
    New Member
    • Dec 2009
    • 1

    #1

    XSL setting flag variables

    Here is a sample of the xml file that I have:

    Code:
    <provider>
        <cinames>
            <cinema>
                <id>1111</id>
                <name>ABC cinema</name>
                <address>123 street</address>
            </cinema>
            <cinema>
                <id>2222</id>
                <name>DEF cinema</name>
                <address>456 street</address>
            </cinema>   
            .
            .
            .
        </cinemas>
        <movies>
            <movie>
                <id>9999</id>
                <name>Terminator</name>
                <cinema>
                    <id>1111</id>
                    <name>ABC cinema</name>
                    <showDate>2009-12-01</showDate>
                    <showTime>1000</showTime>
                    <showTime>1230</showTime>
                </cinema>
                <cinema>
                    <id>1111</id>
                    <name>ABC cinema</name>
                    <showDate>2009-12-02</showDate>
                    <showTime>1000</showTime>
                    <showTime>1230</showTime>
                </cinema>
                <cinema>
                    <id>1111</id>
                    <name>ABC cinema</name>
                    <showDate>2009-12-03</showDate>
                    <showTime>1000</showTime>
                    <showTime>1230</showTime>
                </cinema>
                <cinema>
                    <id>2222</id>
                    <name>DEF cinema</name>
                    <showDate>2009-12-01</showDate>
                    <showTime>1000</showTime>
                    <showTime>1230</showTime>
                </cinema>
                <cinema>
                    <id>2222</id>
                    <name>DEF cinema</name>
                    <showDate>2009-12-02</showDate>
                    <showTime>1000</showTime>
                    <showTime>1230</showTime>
                </cinema>           
            </movie>
            <movie>
                <id>8888</id>
                <name>Shrek</name>
                <cinema>
                    <id>1111</id>
                    <name>ABC cinema</name>
                    <showDate>2009-12-01</showDate>
                    <showTime>1000</showTime>
                    <showTime>1230</showTime>
                </cinema>
                <cinema>
                    <id>1111</id>
                    <name>ABC cinema</name>
                    <showDate>2009-12-02</showDate>
                    <showTime>1000</showTime>
                    <showTime>1230</showTime>
                </cinema>
                <cinema>
                    <id>1111</id>
                    <name>ABC cinema</name>
                    <showDate>2009-12-03</showDate>
                    <showTime>1000</showTime>
                    <showTime>1230</showTime>
                </cinema>
                <cinema>
                    <id>2222</id>
                    <name>DEF cinema</name>
                    <showDate>2009-12-01</showDate>
                    <showTime>1000</showTime>
                    <showTime>1230</showTime>
                </cinema>
                <cinema>
                    <id>2222</id>
                    <name>DEF cinema</name>
                    <showDate>2009-12-02</showDate>
                    <showTime>1000</showTime>
                    <showTime>1230</showTime>
                </cinema>           
            </movie>
            .
            .
            .
        </movies>
    </provider>
    Currently my xsl file generates the following:

    ---------------------------------------------------------------
    ABC Cinema (ID: 1111)

    Address: 123 Street

    Movie: Terminator
    Show Date: 2009-12-01
    Show Times: 1000, 1230

    Movie: Terminator
    Show Date: 2009-12-02
    Show Times: 1000, 1230

    Movie: Terminator
    Show Date: 2009-12-03
    Show Times: 1000, 1230

    Movie: Shrek
    Show Date: 2009-12-01
    Show Times: 1000, 1230

    Movie: Shrek
    Show Date: 2009-12-02
    Show Times: 1000, 1230

    Movie: Shrek
    Show Date: 2009-12-01
    Show Times: 1000, 1230
    -----------------------------------------------------------------

    DEF Cinema (ID:2222)

    Address: 456 street

    Movie: Terminator
    Show Date: 2009-12-01
    Show Times: 1000, 1230

    Movie: Terminator
    Show Date: 2009-12-02
    Show Times: 1000, 1230

    Movie: Shrek
    Show Date: 2009-12-01
    Show Times: 1000, 1230

    Movie: Shrek
    Show Date: 2009-12-02
    Show Times: 1000, 1230
    ------------------------------------------------------------------------------
    .
    .
    . and so on


    but the thing is i do not want the movie name to be repeated. I just want the movie name to be printed once and followed by all its show dates and corresponding show times. I tried various things like setting a flag variable but but was not successful. I'd appreciate some help!

    Here is my current xsl file:

    Code:
    <?xml version='1.0'?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>
    <xsl:template match="/">
        <xsl:for-each select="provider/cinemas/cinema">
            <hr>
            <xsl:variable name="var_cinemaId" select="id"/>
            <font size="4"><b><xsl:value-of select="name"/> (ID: <xsl:value-of select="id"/>)</b></font><br/><br/>
            <b>Address: </b><xsl:value-of select="address"/>
            <br/><br/>
            <xsl:for-each select="/provider/movies/movie">
                <xsl:variable name="var_movieName" select="name"/>
                <xsl:for-each select="cinema">
                    <xsl:if test="id=$var_cinemaId">
                        <b>Movie: </b> <xsl:value-of select="$var_movieName"/><br/>
                        <b>Show Date: </b> <xsl:value-of select="showDate"/><br/>
                        <b>Show Times: </b>
                        <xsl:for-each select="showTime">
                            <xsl:value-of select="."/>, &#xa0;
                        </xsl:for-each>
                        <br/><br/>
                    </xsl:if>
                </xsl:for-each>
            </xsl:for-each>
        </hr>       
        </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
    Ultimately, I want the xsl file to generate the following:

    ---------------------------------------------------------------
    ABC Cinema (ID: 1111)

    Address: 123 Street

    Movie: Terminator
    Show Date: 2009-12-01
    Show Times: 1000, 1230

    Show Date: 2009-12-02
    Show Times: 1000, 1230

    Show Date: 2009-12-03
    Show Times: 1000, 1230

    Movie: Shrek
    Show Date: 2009-12-01
    Show Times: 1000, 1230

    Show Date: 2009-12-02
    Show Times: 1000, 1230

    Show Date: 2009-12-01
    Show Times: 1000, 1230
    -----------------------------------------------------------------

    DEF Cinema (ID:2222)

    Address: 456 street

    Movie: Terminator
    Show Date: 2009-12-01
    Show Times: 1000, 1230

    Show Date: 2009-12-02
    Show Times: 1000, 1230

    Movie: Shrek
    Show Date: 2009-12-01
    Show Times: 1000, 1230

    Show Date: 2009-12-02
    Show Times: 1000, 1230
    ------------------------------------------------------------------------------
    .
    .
    and so on

    Thanks!
    Last edited by Dormilich; Dec 8 '09, 08:17 PM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    if I remember right you need Munchian Sorting (wish I knew in which thread the link was in)

    Comment

    Working...