[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Row/Col Span

Subject: Row/Col Span
From: Cleyton Jordan <cleytonjordan@xxxxxxxxxxx>
Date: Thu, 7 May 2009 02:52:22 -0700 (PDT)
 Row/Col Span
Hi,

I have written the XSLT below to figure out the number of rows and columns so
that I can add the rowspan and colspan to a <TD> element and it seems to be
working.

However, I am not sure if this is the best and most effective way to do it in
XSLT and would appreciate very much your comments and maybe if there is better
approach I would be thankful if you could share it with us.

Please note that I am using XSLT 1.0 and msxml

Given this xml:

1 - the colspan would be 2 (1 ColGrp + 1 Col)
2 - the rowsapn would be 2 (1 RowGrp + 1 Row)

<Report>
 <Columns>
    <ColGrp heading="Year">
      <Col heading="2003"/>
      <Col heading="2004"/>
    </ColGrp>
    <ColGrp heading="">
      <Col heading="Total"/>
    </ColGrp>
  </Columns>
  <Rows>
      <RowGrp heading="Journal Group Name">
        <Row heading="Gastroenterology">
          <Cell/>
          </Cell>
        </Row>
        <Row heading="Pharmacy">
          <Cell/>
          <Cell/>
        </Row>
      </RowGrp>
      <RowGrp heading="">
        <Row heading="Totals">
          <Cell/>
          <Cell/>
        </Row>
      </RowGrp>
  </Rows>
</Report>

I would like to point out that I can have many <ColGrp> elements child of
<ColGrp>. Similarly, I may have many <RowGrp> elements. Therefore, I need a
dynamic way to count all ColGrp/RowGrp + 1 for the Col/Row

3 - here the colspan would be 4 ( ColGrp + ColGrp + ColGrp + Col)

<Columns>
 <ColGrp heading="Test">
   <ColGrp heading="Test">
     <ColGrp heading="Year">
       <Col heading="2003"/>
       <Col heading="2004"/>
     </ColGrp>
     <ColGrp heading="">
       <Col heading="Total"/>
     </ColGrp>
   </ColGrp>
 </ColGrp>
</Columns>

+++++

4 - here the rowspan would be 3 (RowGrp + RowGrp + Row)

<Rows>
    <RowGrp heading="Media Full Name">
      <RowGrp heading="Oncology">
        <Row heading="Blood">
          <Cell/>
        </Row>
        <Row heading="Oncology News International">
          <Cell/>
        </Row>
      </RowGrp>
    </RowGrp>
    <RowGrp>
      <RowGrp>
        <Row heading="Total">
          <Cell/>
        </Row>
      </RowGrp>
    </RowGrp>
  </Rows>

 As you can see I need to work with only one ColGrp or RowGrp.

This is the extract of the XSLT I am using:

<xsl:variable name="row-span">
    <xsl:call-template name="count-row-span">
      <xsl:with-param name="set" select="/Report/Columns/ColGrp"/>
      <xsl:with-param name="rowcount" select="0"/>
    </xsl:call-template>
  </xsl:variable>

  <xsl:variable name="col-span">
    <xsl:call-template name="count-col-span">
      <xsl:with-param name="set" select="/Report/Rows/RowGrp"/>
      <xsl:with-param name="colcount" select="1"/>
    </xsl:call-template>
  </xsl:variable>

<xsl:template name="count-col-span">
    <xsl:param name="set"/>
    <xsl:param name="colcount"/>
    <xsl:choose>
      <xsl:when test="$set/RowGrp">
        <xsl:call-template name="count-col-span">
          <xsl:with-param name="set" select="$set/*[1]"/>
          <xsl:with-param name="colcount" select="$colcount + 1"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$set/Row">
        <xsl:value-of select ="$colcount + 1"/>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="count-row-span">
  <xsl:param name="set"/>
  <xsl:param name="rowcount"/>
  <xsl:choose>
    <xsl:when test="$set/ColGrp">
       <xsl:call-template name="count-row-span">
        <xsl:with-param name="set" select="$set/*[1]"/>
        <xsl:with-param name="rowcount" select="$rowcount + 1"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="$set/Col">
      <xsl:value-of select ="count($set[1]/Col) + $rowcount + 2"/>
    </xsl:when>
  </xsl:choose>


Cheers

C

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.