Loading ...
Sorry, an error occurred while loading the content.

Table: Alternating background color

Expand Messages
  • Stephen Siu
    Hi all, I was wondering - how would I go about having alternating background colors for each row? For example the first row would be dark gray, next would be
    Message 1 of 5 , Dec 21, 2005
    • 0 Attachment
      Hi all,



      I was wondering - how would I go about having alternating background
      colors for each row? For example the first row would be dark gray, next
      would be light, etc.



      Regards,

      Stephen Siu

      Research In Motion






      ---------------------------------------------------------------------
      This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.


      [Non-text portions of this message have been removed]
    • G. Ken Holman
      ... Generally when using XSLT to produce the XSL-FO one would algorithmically test the parity of the row number at the point of creating the table-cell or
      Message 2 of 5 , Dec 21, 2005
      • 0 Attachment
        At 2005-12-21 14:46 -0500, Stephen Siu wrote:
        >I was wondering - how would I go about having alternating background
        >colors for each row? For example the first row would be dark gray, next
        >would be light, etc.

        Generally when using XSLT to produce the XSL-FO one would
        algorithmically test the parity of the row number at the point of
        creating the table-cell or table-cell contents and set the background
        accordingly:

        You don't give any example input XML vocabulary, so consider that you
        have input as:

        <rows>
        <row>
        ...

        In your XSLT you match on rows and process each row:

        <xsl:template match="rows">
        ...
        <xsl:apply-templates select="row"/>
        ...

        The handling of the row then has the current row in the position in
        the current node list created by selecting all rows; below I put it
        in a variable because I'm guessing the current node will change in
        the processing of the row contents:

        <xsl:template match="row">
        <xsl:variable name="row-pos" select="position()"/>
        ...
        <!--assume background colour-->
        <xsl:attribute name="background-color">white</xsl:attribute>
        <xsl:if test="$row-pos mod 2">
        <xsl:attribute name="background-color">gray</xsl:attribute>
        </xsl:if>
        ...

        The above could be accomplished with many other possible constructs
        based on how you choose to process your XML, but that's the gist. In
        the above I just first assume that the colour is white, then if the
        parity of the row number is odd I change it to gray.

        I hope this helps.

        . . . . . . . . . . Ken


        --
        Upcoming XSLT/XSL-FO hands-on courses: Denver,CO March 13-17,2006
        World-wide on-site corporate, govt. & user group XML/XSL training.
        G. Ken Holman mailto:gkholman@...
        Crane Softwrights Ltd. http://www.CraneSoftwrights.com/f/
        Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
        Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/f/bc
        Legal business disclaimers: http://www.CraneSoftwrights.com/legal
      • Stephen Siu
        Hi Ken, Thanks for responding. Sorry I did not include more information. The inputs into my simple-tables are ... I was not particularly
        Message 3 of 5 , Dec 22, 2005
        • 0 Attachment
          Hi Ken,

          Thanks for responding.

          Sorry I did not include more information. The inputs into my
          simple-tables are

          <strow>
          <stentry>
          ...

          I was not particularly sure what you meant but I put the following in my
          XSLT:

          <xsl:template match="strow">
          <xsl:apply-templates select="stentry"/>
          <xsl:variable name="row-pos" select="position()"/>
          <xsl:attribute name="background-color">
          <xsl:choose>
          <xsl:when test="$row-pos mod 2">blue</xsl:when>
          <xsl:otherwise>grey</xsl:otherwise>
          </xsl:choose>
          </xsl:attribute>
          </xsl:template>

          Because I noticed earlier in my XSLT that I performed conditionality
          tests using "choose". However, this code produces an error which I
          cannot debug.

          I was generally unsure how you set up the markup in your explanation.
          Thanks for your help :)

          -----Original Message-----
          From: XSL-FO@yahoogroups.com [mailto:XSL-FO@yahoogroups.com] On Behalf
          Of G. Ken Holman
          Sent: December 21, 2005 3:21 PM
          To: XSL-FO@yahoogroups.com
          Subject: Re: [XSL-FO] Table: Alternating background color

          At 2005-12-21 14:46 -0500, Stephen Siu wrote:
          >I was wondering - how would I go about having alternating background
          >colors for each row? For example the first row would be dark gray, next
          >would be light, etc.

          Generally when using XSLT to produce the XSL-FO one would
          algorithmically test the parity of the row number at the point of
          creating the table-cell or table-cell contents and set the background
          accordingly:

          You don't give any example input XML vocabulary, so consider that you
          have input as:

          <rows>
          <row>
          ...

          In your XSLT you match on rows and process each row:

          <xsl:template match="rows">
          ...
          <xsl:apply-templates select="row"/>
          ...

          The handling of the row then has the current row in the position in
          the current node list created by selecting all rows; below I put it
          in a variable because I'm guessing the current node will change in
          the processing of the row contents:

          <xsl:template match="row">
          <xsl:variable name="row-pos" select="position()"/>
          ...
          <!--assume background colour-->
          <xsl:attribute name="background-color">white</xsl:attribute>
          <xsl:if test="$row-pos mod 2">
          <xsl:attribute name="background-color">gray</xsl:attribute>
          </xsl:if>
          ...

          The above could be accomplished with many other possible constructs
          based on how you choose to process your XML, but that's the gist. In
          the above I just first assume that the colour is white, then if the
          parity of the row number is odd I change it to gray.

          I hope this helps.

          . . . . . . . . . . Ken


          --
          Upcoming XSLT/XSL-FO hands-on courses: Denver,CO March 13-17,2006
          World-wide on-site corporate, govt. & user group XML/XSL training.
          G. Ken Holman mailto:gkholman@...
          Crane Softwrights Ltd. http://www.CraneSoftwrights.com/f/
          Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
          Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/f/bc
          Legal business disclaimers: http://www.CraneSoftwrights.com/legal





          Yahoo! Groups Links









          ---------------------------------------------------------------------
          This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.
        • G. Ken Holman
          ... But my example started from one level higher, at the collection of rows. ... I was not trying to give you code to insert but a guideline for you to follow.
          Message 4 of 5 , Dec 22, 2005
          • 0 Attachment
            At 2005-12-22 16:18 -0500, Stephen Siu wrote:
            >Sorry I did not include more information. The inputs into my
            >simple-tables are
            >
            ><strow>
            > <stentry>
            > ...

            But my example started from one level higher, at the collection of rows.

            >I was not particularly sure what you meant but I put the following in my
            >XSLT:

            I was not trying to give you code to insert but a guideline for you to follow.

            >However, this code produces an error which I cannot debug.

            Not surprising since my example was merely a guideline.

            >I was generally unsure how you set up the markup in your explanation.

            My point was that at the part of your stylesheet where you process a
            set of rows, put the position of each row in a variable so that when
            you process the entries in the row you have access to the row
            variable to do the parity test.

            So I'm guessing you have:

            <sttable>
            <strow>
            <stentry>

            In your XSLT you match on rows and process each row:

            <xsl:template match="sttable">
            ...setting up the table...
            <xsl:apply-templates select="strow"/>
            ...finishing up the table...

            The handling of the row then has the current row in the position in
            the current node list created by selecting all rows; below I put it
            in a variable because I'm guessing the current node will change in
            the processing of the row contents:

            <xsl:template match="strow">
            <xsl:variable name="row-pos" select="position()"/>
            ...setting up the row...
            <xsl:for-each select="stentry">
            ...setting up the column...
            <!--assume background colour-->
            <xsl:attribute name="background-color">white</xsl:attribute>
            <xsl:if test="$row-pos mod 2">
            <xsl:attribute name="background-color">gray</xsl:attribute>
            </xsl:if>

            But, again, you've given so very little of your requirement that the
            above is *only* meant to be a guideline. The "..." bits are for you
            to replace with whatever your requirement is for your output.

            I hope this helps.

            . . . . . . . . . . Ken

            --
            Upcoming XSLT/XSL-FO hands-on courses: Denver,CO March 13-17,2006
            World-wide on-site corporate, govt. & user group XML/XSL training.
            G. Ken Holman mailto:gkholman@...
            Crane Softwrights Ltd. http://www.CraneSoftwrights.com/f/
            Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
            Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/f/bc
            Legal business disclaimers: http://www.CraneSoftwrights.com/legal
          • vijay chiniwar
            Hi I used this, and i get alternate colours,
            Message 5 of 5 , Jan 6, 2006
            • 0 Attachment
              Hi

              I used this, and i get alternate colours,

              <xsl:for-each select="/screening/company-ticker">
              <xsl:choose >
              <xsl:when test="position() mod 2 = 0">
              <fo:table-row background-color="grey" >
              ......
              </fo:table-row>
              </xsl:when>
              <xsl:otherwise >
              <fo:table-row background-color="white">
              ......

              </fo:table-row>
              </xsl:otherwise>
              </xsl:choose >
              </xsl:for-each>




              Stephen Siu <ssiu@...> wrote:
              Hi Ken,

              Thanks for responding.

              Sorry I did not include more information. The inputs into my
              simple-tables are

              <strow>
              <stentry>
              ...

              I was not particularly sure what you meant but I put the following in my
              XSLT:

              <xsl:template match="strow">
              <xsl:apply-templates select="stentry"/>
              <xsl:variable name="row-pos" select="position()"/>
              <xsl:attribute name="background-color">
              <xsl:choose>
              <xsl:when test="$row-pos mod 2">blue</xsl:when>
              <xsl:otherwise>grey</xsl:otherwise>
              </xsl:choose>
              </xsl:attribute>
              </xsl:template>

              Because I noticed earlier in my XSLT that I performed conditionality
              tests using "choose". However, this code produces an error which I
              cannot debug.

              I was generally unsure how you set up the markup in your explanation.
              Thanks for your help :)

              -----Original Message-----
              From: XSL-FO@yahoogroups.com [mailto:XSL-FO@yahoogroups.com] On Behalf
              Of G. Ken Holman
              Sent: December 21, 2005 3:21 PM
              To: XSL-FO@yahoogroups.com
              Subject: Re: [XSL-FO] Table: Alternating background color

              At 2005-12-21 14:46 -0500, Stephen Siu wrote:
              >I was wondering - how would I go about having alternating background
              >colors for each row? For example the first row would be dark gray, next
              >would be light, etc.

              Generally when using XSLT to produce the XSL-FO one would
              algorithmically test the parity of the row number at the point of
              creating the table-cell or table-cell contents and set the background
              accordingly:

              You don't give any example input XML vocabulary, so consider that you
              have input as:

              <rows>
              <row>
              ...

              In your XSLT you match on rows and process each row:

              <xsl:template match="rows">
              ...
              <xsl:apply-templates select="row"/>
              ...

              The handling of the row then has the current row in the position in
              the current node list created by selecting all rows; below I put it
              in a variable because I'm guessing the current node will change in
              the processing of the row contents:

              <xsl:template match="row">
              <xsl:variable name="row-pos" select="position()"/>
              ...
              <!--assume background colour-->
              <xsl:attribute name="background-color">white</xsl:attribute>
              <xsl:if test="$row-pos mod 2">
              <xsl:attribute name="background-color">gray</xsl:attribute>
              </xsl:if>
              ...

              The above could be accomplished with many other possible constructs
              based on how you choose to process your XML, but that's the gist. In
              the above I just first assume that the colour is white, then if the
              parity of the row number is odd I change it to gray.

              I hope this helps.

              . . . . . . . . . . Ken


              --
              Upcoming XSLT/XSL-FO hands-on courses: Denver,CO March 13-17,2006
              World-wide on-site corporate, govt. & user group XML/XSL training.
              G. Ken Holman mailto:gkholman@...
              Crane Softwrights Ltd. http://www.CraneSoftwrights.com/f/
              Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
              Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/f/bc
              Legal business disclaimers: http://www.CraneSoftwrights.com/legal





              Yahoo! Groups Links









              ---------------------------------------------------------------------
              This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.


              SPONSORED LINKS
              Xml xsl Xsl Xsl fo Xsl-fo Xsl tutorial

              ---------------------------------
              YAHOO! GROUPS LINKS


              Visit your group "XSL-FO" on the web.

              To unsubscribe from this group, send an email to:
              XSL-FO-unsubscribe@yahoogroups.com

              Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


              ---------------------------------






              ---------------------------------
              Yahoo! DSL Something to write home about. Just $16.99/mo. or less

              [Non-text portions of this message have been removed]
            Your message has been successfully submitted and would be delivered to recipients shortly.