XSL prob.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas

    XSL prob.

    Hi

    I have an XSL stylesheet:

    <xsl:for-each select="TRACKS/TRACK">
    <tr class="TDL">
    <td width="90%"><xs l:number value="position ()" format="1" /> -
    <xsl:value-of select="TRACKTI TLE"/></td>
    <td width="10%" align="center"> <a href="{TRACKURL }"
    target="_blank" >More info!</a></td>
    </tr>
    </xsl:for-each>


    I wan't to make every second <tr class> aligned to TDU, which I have in the
    CSS. How is this possible?

    Regards,
    Kenneth


  • Marrow

    #2
    Re: XSL prob.

    Hi Kenneth,

    Try one of the following (all do the same - in a slightly different way)...

    <xsl:for-each select="TRACKS/TRACK">
    <tr class="TDL">
    <xsl:if test="position( ) mod 2 = 0">
    <xsl:attribut e name="class">TD U</xsl:attribute>
    </xsl:if>
    <td width="90%">
    <xsl:number value="position ()" format="1" /> -
    <xsl:value-of select="TRACKTI TLE"/>
    </td>
    <td width="10%" align="center">
    <a href="{TRACKURL }" target="_blank" >More info!</a>
    </td>
    </tr>
    </xsl:for-each>

    <xsl:for-each select="TRACKS/TRACK">
    <tr>
    <xsl:attribut e name="class">
    <xsl:choose>
    <xsl:when test="position( ) mod 2 = 1">
    <xsl:text>TDL </xsl:text>
    </xsl:when>
    <xsl:otherwis e>
    <xsl:text>TDU </xsl:text>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>
    <td width="90%">
    <xsl:number value="position ()" format="1" /> -
    <xsl:value-of select="TRACKTI TLE"/>
    </td>
    <td width="10%" align="center">
    <a href="{TRACKURL }" target="_blank" >More info!</a>
    </td>
    </tr>
    </xsl:for-each>

    <xsl:for-each select="TRACKS/TRACK">
    <tr class="{substri ng('TDUTDL',((p osition() mod 2) * 3) + 1,3)}">
    <td width="90%">
    <xsl:number value="position ()" format="1" /> -
    <xsl:value-of select="TRACKTI TLE"/>
    </td>
    <td width="10%" align="center">
    <a href="{TRACKURL }" target="_blank" >More info!</a>
    </td>
    </tr>
    </xsl:for-each>

    Hope this helps
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    Jogue jogos online gratuitos diretamente no seu navegador, no celular, tablet ou computador em Jogos Rix. Não é necessário download nem cadastro.



    "Thomas" <ridder_dk@SLET _DETTEhotmail.c om> wrote in message
    news:Q_mdb.1048 44$Kb2.3913799@ news010.worldon line.dk...[color=blue]
    > Hi
    >
    > I have an XSL stylesheet:
    >
    > <xsl:for-each select="TRACKS/TRACK">
    > <tr class="TDL">
    > <td width="90%"><xs l:number value="position ()" format="1" /> -
    > <xsl:value-of select="TRACKTI TLE"/></td>
    > <td width="10%" align="center"> <a href="{TRACKURL }"
    > target="_blank" >More info!</a></td>
    > </tr>
    > </xsl:for-each>
    >
    >
    > I wan't to make every second <tr class> aligned to TDU, which I have in[/color]
    the[color=blue]
    > CSS. How is this possible?
    >
    > Regards,
    > Kenneth
    >
    >[/color]


    Comment

    • Thomas

      #3
      Re: XSL prob.

      Hi Marrow.

      Damn! You nailed it, thanks.



      "Marrow" <marrow-NO-@-SPAM-marrowsoft.com> wrote in message
      news:UFndb.668$ 9m.313@newsfep1-gui.server.ntli .net...[color=blue]
      > Hi Kenneth,
      >
      > Try one of the following (all do the same - in a slightly different[/color]
      way)...[color=blue]
      >
      > <xsl:for-each select="TRACKS/TRACK">
      > <tr class="TDL">
      > <xsl:if test="position( ) mod 2 = 0">
      > <xsl:attribut e name="class">TD U</xsl:attribute>
      > </xsl:if>
      > <td width="90%">
      > <xsl:number value="position ()" format="1" /> -
      > <xsl:value-of select="TRACKTI TLE"/>
      > </td>
      > <td width="10%" align="center">
      > <a href="{TRACKURL }" target="_blank" >More info!</a>
      > </td>
      > </tr>
      > </xsl:for-each>
      >
      > <xsl:for-each select="TRACKS/TRACK">
      > <tr>
      > <xsl:attribut e name="class">
      > <xsl:choose>
      > <xsl:when test="position( ) mod 2 = 1">
      > <xsl:text>TDL </xsl:text>
      > </xsl:when>
      > <xsl:otherwis e>
      > <xsl:text>TDU </xsl:text>
      > </xsl:otherwise>
      > </xsl:choose>
      > </xsl:attribute>
      > <td width="90%">
      > <xsl:number value="position ()" format="1" /> -
      > <xsl:value-of select="TRACKTI TLE"/>
      > </td>
      > <td width="10%" align="center">
      > <a href="{TRACKURL }" target="_blank" >More info!</a>
      > </td>
      > </tr>
      > </xsl:for-each>
      >
      > <xsl:for-each select="TRACKS/TRACK">
      > <tr class="{substri ng('TDUTDL',((p osition() mod 2) * 3) + 1,3)}">
      > <td width="90%">
      > <xsl:number value="position ()" format="1" /> -
      > <xsl:value-of select="TRACKTI TLE"/>
      > </td>
      > <td width="10%" align="center">
      > <a href="{TRACKURL }" target="_blank" >More info!</a>
      > </td>
      > </tr>
      > </xsl:for-each>
      >
      > Hope this helps
      > Marrow
      > http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
      > http://www.topxml.com/Xselerator
      >
      >
      > "Thomas" <ridder_dk@SLET _DETTEhotmail.c om> wrote in message
      > news:Q_mdb.1048 44$Kb2.3913799@ news010.worldon line.dk...[color=green]
      > > Hi
      > >
      > > I have an XSL stylesheet:
      > >
      > > <xsl:for-each select="TRACKS/TRACK">
      > > <tr class="TDL">
      > > <td width="90%"><xs l:number value="position ()" format="1" /> -
      > > <xsl:value-of select="TRACKTI TLE"/></td>
      > > <td width="10%" align="center"> <a href="{TRACKURL }"
      > > target="_blank" >More info!</a></td>
      > > </tr>
      > > </xsl:for-each>
      > >
      > >
      > > I wan't to make every second <tr class> aligned to TDU, which I have in[/color]
      > the[color=green]
      > > CSS. How is this possible?
      > >
      > > Regards,
      > > Kenneth
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Thomas

        #4
        Re: XSL prob.

        Hi

        I have another prob. Is it possible to convert a unix timestamp to a
        readable date with XSL?

        Kenneth


        Comment

        • Dimitre Novatchev

          #5
          Re: XSL prob.

          Can you give an example of a "Unix timestamp" and a "readable date"?


          =====
          Cheers,

          Dimitre Novatchev.
          http://fxsl.sourceforge.net/ -- the home of FXSL


          "Thomas" <ridder_dk@SLET _DETTEhotmail.c om> wrote in message
          news:vxwdb.1067 01$Kb2.3926642@ news010.worldon line.dk...[color=blue]
          > Hi
          >
          > I have another prob. Is it possible to convert a unix timestamp to a
          > readable date with XSL?
          >
          > Kenneth
          >
          >[/color]


          Comment

          • Thomas

            #6
            Re: XSL prob.

            > Can you give an example of a "Unix timestamp" and a "readable date"?

            Unix timestamp: 875996580
            Readable converted date/time: 1997-10-04 22:23:00'

            Kenneth


            Comment

            • Dimitre Novatchev

              #7
              Re: XSL prob.

              > > Can you give an example of a "Unix timestamp" and a "readable date"?[color=blue]
              >
              > Unix timestamp: 875996580
              > Readable converted date/time: 1997-10-04 22:23:00'[/color]

              And what's its meaning (e.g. number of seconds after some date)?


              =====
              Cheers,

              Dimitre Novatchev.
              http://fxsl.sourceforge.net/ -- the home of FXSL


              Comment

              • Thomas

                #8
                Re: XSL prob.

                > And what's its meaning (e.g. number of seconds after some date)?

                Source: http://www.mysql.com/doc/en/Date_and...functions.html

                It would be a lot easier if they pull the data out of the database as a
                readable date instead of unix timestamp, but they don't. :(

                Regards,

                Kenneth


                Comment

                • Jens M. Felderhoff

                  #9
                  Re: XSL prob.

                  "Thomas" <ridder_dk@SLET _DETTEhotmail.c om> writes:
                  [color=blue]
                  > I have another prob. Is it possible to convert a unix timestamp to a
                  > readable date with XSL?[/color]

                  Yes, because XSLT is Turing complete. However, you'll have to roll
                  your own conversion because there's neither an XSLT nor XPath function
                  that'll do the job for you.

                  Cheers

                  Jens

                  Comment

                  • Martin Boehm

                    #10
                    Re: XSL prob.

                    "Thomas" <ridder_dk@SLET _DETTEhotmail.c om> wrote in message
                    news:7RRdb.1071 41$Kb2.3972494@ news010.worldon line.dk[color=blue][color=green]
                    >> And what's its meaning (e.g. number of seconds after some date)?[/color]
                    >
                    > Source: http://www.mysql.com/doc/en/Date_and...functions.html
                    >
                    > It would be a lot easier if they pull the data out of the database as
                    > a readable date instead of unix timestamp, but they don't. :([/color]

                    Since a UNIX timestamp is the number of seconds since midnight, 1st
                    January 1970, it would be an "easy" addition of seconds to a date. But
                    XSL is not capable of that, AFAICS.

                    What you could do - write a web page accepting a timestamp as GET
                    parameter and let it return a small XML file to your XSL processor.

                    Given a return XML like:
                    <?xml version="1.0"?>
                    <formatted>19 97-10-04 22:23:00</formatted>

                    then I would think of:
                    <xsl:value-of
                    select="documen t(concat('http://localhost/convert.php&amp ;timestamp=',
                    $timestamp))/formatted" />

                    This would return the contents of the XML document's "formatted"
                    element, or what ever you'd like to call it.
                    PHP does contain date and time functions capable of converting
                    timestamps, so the implementation on the PHP side should be quite
                    straightforward .

                    You could even improve performance by handing all timestamps in your
                    document over to PHP simultaneously, as a seperated list of values
                    (build that by recursive call-template's). So you will need to use
                    document() only once per processed XML file.

                    just an idea,

                    Martin


                    Comment

                    • Martin Boehm

                      #11
                      Re: XSL prob.

                      "Jens M. Felderhoff" <j.m.f.dev.null @gmx.net> wrote in message
                      news:bl8ssa$9d7 kh$1@ID-10019.news.uni-berlin.de[color=blue]
                      > "Thomas" <ridder_dk@SLET _DETTEhotmail.c om> writes:
                      >[color=green]
                      >> I have another prob. Is it possible to convert a unix timestamp to a
                      >> readable date with XSL?[/color]
                      >
                      > Yes, because XSLT is Turing complete. However, you'll have to roll
                      > your own conversion [...][/color]

                      Which would cause quite a headache and bury efficiency really big time.
                      XSLT is not the adequate instrument for such a task, except for academic
                      purposes maybe. But regarding the wording of the question you are
                      absolutely right. ;-)

                      Martin


                      Comment

                      • Dimitre Novatchev

                        #12
                        The solution (Was: Re: XSL prob.)


                        "Martin Boehm" <ng.tomalak@arc or.de> wrote in message
                        news:3f7883ce$0 $23106$9b4e6d93 @newsread2.arco r-online.net...[color=blue]
                        > "Jens M. Felderhoff" <j.m.f.dev.null @gmx.net> wrote in message
                        > news:bl8ssa$9d7 kh$1@ID-10019.news.uni-berlin.de[color=green]
                        > > "Thomas" <ridder_dk@SLET _DETTEhotmail.c om> writes:
                        > >[color=darkred]
                        > >> I have another prob. Is it possible to convert a unix timestamp to a
                        > >> readable date with XSL?[/color]
                        > >
                        > > Yes, because XSLT is Turing complete. However, you'll have to roll
                        > > your own conversion [...][/color]
                        >
                        > Which would cause quite a headache and bury efficiency really big time.
                        > XSLT is not the adequate instrument for such a task, except for academic
                        > purposes maybe. But regarding the wording of the question you are
                        > absolutely right. ;-)[/color]

                        This is not true!

                        Using the datetime_lib.xs l stylesheet, which comes with the XSelerator (one
                        can obtain it free with the trial download), the code to convert a Unix
                        timestamp to a formatted date is just a few lines (11 lines for the called
                        template):

                        <xsl:styleshe et version="1.0"
                        xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

                        <xsl:import href="E:\Progra m
                        Files\Marrowsof t\Xselerator25\ Samples\Librari es\datetime_lib .xsl"/>

                        <xsl:output method="text"/>

                        <xsl:variable name="vDaySecs" select="86400"/>

                        <xsl:template match="/">
                        <xsl:call-template name="unix-timestamp-to-datetime">
                        <xsl:with-param name="pTimeStam p" select="8759965 80"/>
                        </xsl:call-template>
                        </xsl:template>

                        <xsl:template name="unix-timestamp-to-datetime">
                        <xsl:param name="pTimeStam p" select="0"/>

                        <xsl:variable name="vBase">
                        <xsl:call-template name="date-to-julian-day">
                        <xsl:with-param name="date" select="'1970-01-01'"/>
                        </xsl:call-template>
                        </xsl:variable>

                        <xsl:call-template name="float-to-date-time">
                        <xsl:with-param name="value" select="$vBase + $pTimeStamp div
                        $vDaySecs"/>
                        </xsl:call-template>
                        </xsl:template>

                        </xsl:stylesheet>

                        When this transformation is applied on any source.xml (not used), the wanted
                        result is produced:

                        1997-10-04T20:23:00


                        To see the real power of this pure XSLT 1.0 library, do have a look at the
                        Calendar Application I wrote two years ago:

                        Jogue jogos online gratuitos diretamente no seu navegador, no celular, tablet ou computador em Jogos Rix. Não é necessário download nem cadastro.


                        FYI, it is really efficient -- on my PC the transformation time is just 93
                        milliseconds.


                        =====
                        Cheers,

                        Dimitre Novatchev.
                        http://fxsl.sourceforge.net/ -- the home of FXSL



                        Comment

                        • Dimitre Novatchev

                          #13
                          Re: The solution (Was: Re: XSL prob.)

                          > To see the real power of this pure XSLT 1.0 library, do have a look at the[color=blue]
                          > Calendar Application I wrote two years ago:
                          >
                          > http://www.topxml.com/code/default.a...20020711152545
                          >
                          > FYI, it is really efficient -- on my PC the transformation time is just 93
                          > milliseconds.[/color]

                          I mean the complete Calendar application, which performs complex
                          calculations for 365 days, 52 weeks and days-in-week, 12 months and 4
                          quarters.

                          [color=blue]
                          >
                          >
                          > =====
                          > Cheers,
                          >
                          > Dimitre Novatchev.
                          > http://fxsl.sourceforge.net/ -- the home of FXSL
                          >
                          >
                          >[/color]


                          Comment

                          • Martin Boehm

                            #14
                            Re: The solution (Was: Re: XSL prob.)

                            "Dimitre Novatchev" <dnovatchev@yah oo.com> wrote in message
                            news:bla1qb$9p0 vp$1@ID-152440.news.uni-berlin.de
                            [color=blue][color=green][color=darkred]
                            >>>> I have another prob. Is it possible to convert a unix timestamp to
                            >>>> a readable date with XSL?
                            >>>
                            >>> Yes, because XSLT is Turing complete. However, you'll have to roll
                            >>> your own conversion [...][/color]
                            >>
                            >> Which would cause quite a headache and bury efficiency really big
                            >> time. XSLT is not the adequate instrument for such a task, except
                            >> for academic purposes maybe. But regarding the wording of the
                            >> question you are absolutely right. ;-)[/color]
                            >
                            > This is not true!
                            >
                            > [example snipped][/color]

                            I admit, I was not aware of that.
                            [color=blue]
                            > [...]
                            >
                            > FYI, it is really efficient -- on my PC the transformation time is
                            > just 93 milliseconds.[/color]

                            Whatever "my PC" means. SCNR ;-) Besides that you forgot to compare it
                            to the time maybe PHP would need to do it. The word "efficient" is quite
                            meaningless if you give only one number.

                            BTW I am not sure if one can call doing about 10 conversions per second
                            "efficient" in context of the simplicity of this task, given the
                            hardware that you use.

                            What I thought of was putting the algorithms together myself, and my
                            subjective impression was that the outcome would not be optimal under
                            the best of circumstances, and that it would not approximate solutions
                            more adequate for the problem.

                            Martin


                            Comment

                            • Dimitre Novatchev

                              #15
                              Re: The solution (Was: Re: XSL prob.)

                              > > FYI, it is really efficient -- on my PC the transformation time is[color=blue][color=green]
                              > > just 93 milliseconds.[/color]
                              >
                              > Whatever "my PC" means. SCNR ;-)[/color]

                              My PC is 2 years old 1.7GHz Pentium with 256MB RAM running W2K
                              [color=blue]
                              > Besides that you forgot to compare it
                              > to the time maybe PHP would need to do it. The word "efficient" is quite
                              > meaningless if you give only one number.[/color]

                              By efficient I mean that it is not obviously a bottleneck. In this case one
                              would use an existing solution, which BTW is 100% portable.
                              [color=blue]
                              >
                              > BTW I am not sure if one can call doing about 10 conversions per second
                              > "efficient" in context of the simplicity of this task, given the
                              > hardware that you use.[/color]

                              You misunderstood me -- the reported time was for the complete Calendar
                              Application, which does many hundreds of times more...

                              The time for a single conversion using MSXML4 on my PC is 0.3 milliseconds.


                              =====
                              Cheers,

                              Dimitre Novatchev.
                              http://fxsl.sourceforge.net/ -- the home of FXSL


                              Comment

                              Working...