Sorting the element with in the sorting element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saran3b2
    New Member
    • Aug 2007
    • 19

    Sorting the element with in the sorting element

    Hi all,

    If u know the solution please suggest me. I need these urgent.

    production.xml
    [code=xml]
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="xsl/vinoth-new.xsl"?>
    <report>
    <production>
    <etype>Break</etype>
    <user>thiyagu </user>
    <date>3/5/2008</date>
    <book>Traning </book>
    <file>Programmi ng</file>
    <status>WIP</status>
    <task>RND</task>
    <starttime>11:2 4:23 PM</starttime>
    <endtime>11:46: 21 PM</endtime>
    <totaltime> 22</totaltime>
    <updateto/>
    <comment>Tea Break</comment>
    </production>
    <production>
    <etype>Break</etype>
    <user>saravanan </user>
    <date>3/5/2008</date>
    <book>Traning </book>
    <file>Programmi ng</file>
    <status>WIP</status>
    <task>RND</task>
    <starttime>11:2 4:23 PM</starttime>
    <endtime>11:46: 21 PM</endtime>
    <totaltime>5</totaltime>
    <updateto/>
    <comment>Tea Break</comment>
    </production>
    <production>
    <etype>Job</etype>
    <user>sai</user>
    <date>3/6/2008</date>
    <book>aw</book>
    <file>`af</file>
    <status>ar </status>
    <task>Templat e</task>
    <starttime>2:23 :58 PM</starttime>
    <endtime>2:24:0 5 PM</endtime>
    <totaltime> 1</totaltime>
    <updateto>awd </updateto>
    <comment>ef</comment>
    </production>
    <production>
    <etype>job</etype>
    <user>saravanan </user>
    <date>3/5/2008</date>
    <book>Traning </book>
    <file>Programmi ng</file>
    <status>WIP</status>
    <task>RND</task>
    <starttime>01:4 6:21 PM</starttime>
    <endtime>02:46: 21 PM</endtime>
    <totaltime>2</totaltime>
    <updateto/>
    <comment>QC pending</comment>
    </production>
    <production>
    <etype>Job</etype>
    <user>kapil</user>
    <date>3/6/2008</date>
    <book>dcadcad </book>
    <file>adcadc</file>
    <status>OVER</status>
    <task>XML</task>
    <starttime>2:19 :02 AM</starttime>
    <endtime>2:19:1 9 PM</endtime>
    <totaltime> 0</totaltime>
    <updateto>adcad cac</updateto>
    <comment>adcadc a</comment>
    </production>
    <production>
    <etype>Job</etype>
    <user>ksaravana n</user>
    <date>3/6/2008</date>
    <book>aw</book>
    <file>`af</file>
    <status>ar</status>
    <task>Templat e</task>
    <starttime>2:23 :58 PM</starttime>
    <endtime>2:24:0 5 PM</endtime>
    <totaltime> 1</totaltime>
    <updateto>awd </updateto>
    <comment>ef</comment>
    </production>
    <production>
    <etype>Job</etype>
    <user>vinoth</user>
    <date>3/6/2008</date>
    <book>meiners </book>
    <file>chapter 4</file>
    <status>qc</status>
    <task>XML</task>
    <starttime>6:52 :44 PM</starttime>
    <endtime>6:53:3 6 PM</endtime>
    <totaltime> 1</totaltime>
    <updateto>add </updateto>
    <comment>xfb </comment>
    </production>
    <production>
    <etype>Break</etype>
    <user>vinoth</user>
    <date>3/6/2008</date>
    <book>meiners </book>
    <file>chapter 4</file>
    <status>qc</status>
    <task>XML</task>
    <starttime>6:52 :44 PM</starttime>
    <endtime>6:53:3 6 PM</endtime>
    <totaltime> 1</totaltime>
    <updateto>add </updateto>
    <comment>xfb </comment>
    </production>
    </report>
    [/code]

    I want to display these element as

    sort with date
    sort with task with in date
    sort user with in task
    sort etype with in user






    now my xsl

    [code=xml]
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="ISO-8859-1" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/>
    <xsl:variable name="report" select="//production"/>
    <!-- Define keys used to group elements -->
    <xsl:key name="keyDate" match="producti on" use="date" />
    <xsl:key name="keyUser" match="producti on" use="user" />
    <xsl:key name="keyTask" match="producti on" use="task" />
    <xsl:key name="keyEtype" match="producti on" use="etype" />

    <xsl:template match="/">
    <html>
    <head>
    <title>Cengag e Production Report</title>
    </head>
    <body>
    <center>******* *************** *************** ***</center>
    <center><font size="6" color="brown">P reMedia Global P. Ltd.</font>
    </center>
    <center>******* *************** *************** ***</center>

    <center><font size="4" color="blue">Ce ngage Production Report</font></center><br/>



    <table width="80%" frame="box" border="2" align="center">
    <tbody>
    <xsl:apply-templates/>
    </tbody>
    </table>

    </body>
    </html>
    </xsl:template>


    <xsl:template match="report" name="Showprodu ctionsInTeam">

    <xsl:for-each select="$report ">


    <xsl:sort select="date" order="ascendin g"/>


    <xsl:for-each select="$report[generate-id(.) = generate-id(key('keyTask ', task)[1])]">
    <xsl:sort select="task" order="ascendin g"/>
    </xsl:for-each>



    <xsl:variable name="date" select="date"/>

    <xsl:if test="generate-id(.)=generate-id($report[date=$date])">

    <tr>
    <td width="10%" colspan="8" align="center"> <font size="5" color="Green">D ate: <xsl:value-of select="date"/></font></td>
    </tr>
    </xsl:if>

    <xsl:for-each select="$report[generate-id(.) = generate-id(key('keyDate ', date)[1])]">
    <xsl:sort select="task" order="ascendin g"/>
    </xsl:for-each>

    <xsl:variable name="task" select="task"/>
    <xsl:if test="generate-id(.)=generate-id($report[task=$task]) or generate-id(.)=generate-id($report[date=$date])">
    <tr bgcolor="#9e7bf f">
    <td width="10%" colspan="8"><h3 ><xsl:value-of select="task"/></h3></td>
    </tr>
    </xsl:if>

    <xsl:for-each select="$report[generate-id(.) = generate-id(key('keyDate ', date)[1])]">
    <xsl:sort select="user" order="ascendin g"/>
    </xsl:for-each>

    <xsl:variable name="user" select="user"/>
    <xsl:if test="generate-id(.)=generate-id($report[user=$user]) or generate-id(.)=generate-id($report[date=$date])">
    <tr bgcolor="#ddddd d">
    <td width="10%" colspan="8"><fo nt color="blue" size="4"><xsl:v alue-of select="user"/></font></td>
    </tr>
    </xsl:if>

    <xsl:for-each select="$report[generate-id(.) = generate-id(key('keyUser ', user)[1])]">
    <xsl:sort select="etype" order="ascendin g"/>
    </xsl:for-each>

    <xsl:variable name="etype" select="etype"/>
    <xsl:if test="generate-id(.)=generate-id($report[etype=$etype]) or generate-id(.)=generate-id($report[user=$user])">
    <tr>
    <th width="10%">Boo k</th>
    <th width="10%">Fil e</th>
    <th width="10%">Sta tus</th>
    <th width="10%">Sta rt Time</th>
    <th width="10%">End Time</th>
    <th width="10%">Tot al time</th>
    <th width="10%">Upd ated To</th>
    <th width="10%">Com ment</th>
    </tr>
    </xsl:if>

    <tr>
    <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="book" /></td>
    <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="file" /></td>
    <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="status" /></td>
    <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="startti me" /></td>
    <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="endtime " /></td>
    <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="totalti me" /></td>
    <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="updatet o" /></td>
    <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="comment " /></td>
    </tr>


    <xsl:variable name="totaltime " select="totalti me"/>
    <xsl:if test="generate-id(.)=generate-id($report[user=$user]) ">
    <tr>
    <th colspan="8" align="right">< font color="blue">To tal time: <xsl:value-of select="sum($re port[user=$user]/totaltime)" /> minutes</font></th>
    </tr>
    </xsl:if>



    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>
    [/code]


    Advance thanks for ur help
    Last edited by jkmyoung; Mar 7 '08, 10:09 PM. Reason: prettyprinted
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Hi,

    Could you re-post using code tags, otherwise it's difficult to say what row needs attention.

    Thanks

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      I think the word for it is subsort.

      In this case you simply need an additional <xsl:sort/> element

      But to be honest, I'm really not sure what you're trying to do.. the xsl is quite messy. things like
      <xsl:for-each select="$report[generate-id(.) = generate-id(key('keyTask ', task)[1])]">
      <xsl:sort select="task" order="ascendin g"/>
      </xsl:for-each>

      do absolutely nothing, and shouldn't be in the code.

      Comment

      • saran3b2
        New Member
        • Aug 2007
        • 19

        #4
        Hi MarkoKlacar,

        Thanks 4 ur reply. As per previous mail. I have the (etype, user, book, file, status, task, starttime, endtime, totaltime, updateto, comment) elements. Here i want display these elements in stylesheet by

        Date wise then task wise (All are must be ascending order in sub sorting) then user wise like as below mentioned:

        Date: 2/5/2008

        Task: RND

        User: Thiyagu

        Then display Book, file, status,........ .........
        ------------------------------------------------------------------------------------------

        Date: 3/5/2008

        Task: QC

        User: Thiyagu

        Then display Book, file, status,........ .........
        ------------------------------------------------------------------------------------------

        And finally i want total time for each user by date wise.

        I think this may be clear to u. Further any doubt i will like to explain details manner. (My E-mail id: kuberan.vinoth@ gmail.com)


        <report>
        <production>
        <etype>Break</etype>
        <user>thiyagu </user>
        <date>2/5/2008</date>
        <book>Traning </book>
        <file>Programmi ng</file>
        <status>WIP</status>
        <task>QC</task>
        <starttime>11:2 4:23 PM</starttime>
        <endtime>11:46: 21 PM</endtime>
        <totaltime> 22</totaltime>
        <updateto/>
        <comment>Tea Break</comment>
        </production>
        <production>
        <etype>Break</etype>
        <user>thiyagu </user>
        <date>3/5/2008</date>
        <book>Traning </book>
        <file>Programmi ng</file>
        <status>WIP</status>
        <task>RND</task>
        <starttime>11:2 4:23 PM</starttime>
        <endtime>11:46: 21 PM</endtime>
        <totaltime> 22</totaltime>
        <updateto/>
        <comment>Tea Break</comment>
        </production>
        ------ and so on
        </report




        Originally posted by MarkoKlacar
        Hi,

        Could you re-post using code tags, otherwise it's difficult to say what row needs attention.

        Thanks

        Comment

        • saran3b2
          New Member
          • Aug 2007
          • 19

          #5
          hi,

          please ignore that watch the my reply to MarkoKlacar for clear doubt

          Originally posted by jkmyoung
          I think the word for it is subsort.

          In this case you simply need an additional <xsl:sort/> element

          But to be honest, I'm really not sure what you're trying to do.. the xsl is quite messy. things like
          <xsl:for-each select="$report[generate-id(.) = generate-id(key('keyTask ', task)[1])]">
          <xsl:sort select="task" order="ascendin g"/>
          </xsl:for-each>

          do absolutely nothing, and shouldn't be in the code.

          Comment

          • jkmyoung
            Recognized Expert Top Contributor
            • Mar 2006
            • 2057

            #6
            This took awhile:
            [code=xml]
            <xsl:template match="report" name="Showprodu ctionsInTeam">
            <xsl:for-each select="$report[generate-id(.) = generate-id(key('keyDate ', date)[1])]"><!-- Get unique dates -->
            <xsl:sort select="date" order="ascendin g"/>
            <xsl:variable name="date" select="date"/>
            <!-- output date information -->
            <tr>
            <td width="10%" colspan="8" align="center"> <font size="5" color="Green">D ate: <xsl:value-of select="date"/></font></td>
            </tr>
            <xsl:for-each select="key('ke yDate')[generate-id(.) = generate-id(key('keyTask ', concat(date,tas k))[1])]"> <!-- Get unique tasks within a date -->
            <xsl:sort select="task" order="ascendin g"/>
            <!-- output task information -->
            <tr bgcolor="#9e7bf f">
            <td width="10%" colspan="8"><h3 ><xsl:value-of select="task"/></h3></td>
            </tr>

            <xsl:for-each select="key('ke yTask', concat(date,tas k))[count(. | key('keyDateTas kUser', concat(date, task,user))[1]) = 1]"><!-- get unique users within a dateTask -->
            <xsl:sort select="user" order="ascendin g"/>
            <!-- output user information -->
            <tr bgcolor="#ddddd d">
            <td width="10%" colspan="8"><fo nt color="blue" size="4"><xsl:v alue-of select="user"/></font></td>
            </tr>
            <xsl:for-each select="key('ke yDateTaskUser', concat(date, task,user))[count (. | key('keyDateTas kUserEtype',con cat(date, task,user,etype ))[1]) = 1]">
            <xsl:sort select="etype" order="ascendin g"/> <!-- get unique etypes within a date task user. -->
            <tr>
            <th width="10%">Boo k</th>
            <th width="10%">Fil e</th>
            <th width="10%">Sta tus</th>
            <th width="10%">Sta rt Time</th>
            <th width="10%">End Time</th>
            <th width="10%">Tot al time</th>
            <th width="10%">Upd ated To</th>
            <th width="10%">Com ment</th>
            </tr>
            </xsl:for-each>
            <xsl:for-each select="key('ke yDateTaskUserEt ype',concat(dat e, task,user,etype ))">
            <tr>
            <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="book" /></td>
            <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="file" /></td>
            <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="status" /></td>
            <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="startti me" /></td>
            <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="endtime " /></td>
            <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="totalti me" /></td>
            <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="updatet o" /></td>
            <td width="10%" bgcolor="#ddddd d"><xsl:valu e-of select="comment " /></td>
            </tr>
            </xsl:for-each><!-- etype -->
            <tr><!-- This doesn't work, if a user is in multiple days-->
            <th colspan="8" align="right">< font color="blue">To tal time: <xsl:value-of select="sum($re port[user=$user]/totaltime)" /> minutes</font></th>
            </tr>
            </xsl:for-each><!-- user -->
            </xsl:for-each><!-- task -->
            </xsl:for-each><!-- date -->
            </xsl:template>
            [/code]

            Comment

            Working...