Results 1 to 3 of 3

Thread: Help Reducing Code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    66

    Help Reducing Code

    I am new to XSLT. I am trying to use it to generate web based reports. below is a section of the XSLT that is located in a template
    Code:
    <table>
      <thead>
        <td>New Business</td>
      </thead>
      <xsl:apply-templates select="tbl_sp_Test_2_s">
        <xsl:with-param name="type" select="'New Business'"/>
      </xsl:apply-templates>
      <tfoot>
        <td>Number of Sales: <xsl:value-of select="count(tbl_sp_Test_2_s[Business = 'New Business']/Company)"/></td>
        <td class="Amount">New Business Total: <xsl:value-of select="sum(tbl_sp_Test_2_s[Business = 'New Business']/NetRevenue)"/></td>
      </tfoot>
    </table>
    <HR class="SectionBreak"/>
    <table>
      <thead>
        <td>Renewal</td>
      </thead>
      <xsl:apply-templates select="tbl_sp_Test_2_s">
        <xsl:with-param name="type" select="'Renewal'"/>
      </xsl:apply-templates>
      <tfoot>
        <td>Number of Sales: <xsl:value-of select="count(tbl_sp_Test_2_s[Business = 'Renewal']/Company)"/></td>
        <td class="Amount">Renewal Total: <xsl:value-of select="sum(tbl_sp_Test_2_s[Business = 'Renewal']/NetRevenue)"/></td>
      </tfoot>
    </table>
    
    
    <xsl:template match="tbl_sp_Test_2_s">
      <xsl:param name="type"/>
      <xsl:if test="Business = $type">
        <tr>
          <td><xsl:value-of select="Company"/></td>
          <td class="Amount"><xsl:value-of select="NetRevenue"/></td>
        </tr>
      </xsl:if>
    </xsl:template>
    Is there way to set up the template so I don't have the create a static header and footer?

    my XML file look like this
    Code:
    <Root>
      <tbl_sp_Test_1_s>
        <SalesPerson>John Doe</SalesPerson>
        <tbl_sp_Test_2_s>
          <Business>[New Business or Renewal]</Business>
          <Company>Amce Inc.</Company>
          <NetRevenue>1000</NetRevenue>
        </tbl_sp_Test_2_s>
        ...
      </tbl_sp_Test_1_s>
      ...
    </Root>
    Thank you for your assistance
    Jason Meckley
    Database Analyst
    WITF

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I don't quite understand your question. What's bad about a static header and footer, what do you want instead?

    BTW, you're missing the <tr> tags in your header and footer.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    66
    I would like to have it dynamic, so i would only need to write the header/footer once, and then refence that section and pass a variable.

    something like
    Code:
    <template for table>
      <parameter name="P">
      <table>
        <thead>
          <tr>
            <td>$P</td>
          </tr>
        </thead>
        <xsl:apply-templates select="tbl_sp_Test_2_s">
          <xsl:with-param name="type" select=$P/>
        </xsl:apply-templates>
        <tfoot>
          <td>Number of Sales: <xsl:value-of select="count(tbl_sp_Test_2_s[Business = $P]/Company)"/></td>
          <td class="Amount">Renewal Total: <xsl:value-of select="sum(tbl_sp_Test_2_s[Business = $P]/NetRevenue)"/></td>
        </tfoot>
      </table>
    </template for table>
    Then I could reference this template in the previous template with a simple
    Code:
      <table template>
        <with-paramter name="P" select="'New Business'">
      </table template>
      <table template>
        <with-paramter name="P" select="'Renewal'">
      </table template>
    The tutorials I have read say a template needs to reference a node in the xml, so I don't know how (or if it's possible) to create something like this, since my header and footer are not nodes.

    Does this make sense?
    Jason Meckley
    Database Analyst
    WITF

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width