Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 29th, 2005, 08:25 AM
Registered User
 
Join Date: Aug 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Urgent Help

hello,

I am trying to render an xml file but I am having problems trying to get the record count for the categories and the total amount (Pi in the XML) for each category. I am posting the XML and the XSL I have to see if someone could help me. It supposed to be something very simple but I spend 3 days working out solutions but nothing works. Any help will be greatly appreciated, thanks

Report 12/21/2005

Total: 4 11.00
Total A: ? ?
Total AB: ? ?
Total ABC: ? ?

XML:

<?xml version="1.0" standalone="yes"?>
<Reports>
  <Entry>
    <uniqueID>4</uniqueID>
    <date>12/21/2005</date>
    <sNo>9000</sNo>
    <sID>661</sID>
    <Pi>2.0000</Pi>
    <sName>Test Test</sName>
    <sRName>SMITH</sRName>
    <sRNameL>KKL</sRNameL>
    <Category>1</Category>
    <sInterNo />
    <sInterR>0</sInterR>
  </Entry>
  <Entry>
    <uniqueID>5</uniqueID>
    <date>12/21/2005</date>
    <sNo>9000</sNo>
    <sID>622</sID>
    <Pi>3.0000</Pi>
    <sName>Test Test</sName>
    <sRName>POWELL</sRName>
    <sRNameL>KKL</sRNameL>
    <Category>2</Category>
    <sInterNo>445544</sInterNo>
    <sInterR>2</sInterR>
  </Entry>
  <Entry>
    <uniqueID>385473</uniqueID>
    <date>12/20/2005</date>
    <sNo>9000</sNo>
    <sID>189</sID>
    <Pi>2.0000</Pi>
    <sName>Test Test</sName>
    <sRName>JIMTON</sRName>
    <sRNameL>KKL</sRNameL>
    <Category>2</Category>
    <sInterNo>123456</sInterNo>
    <sInterR>2</sInterR>
  </Entry>
  <Entry>
    <uniqueID>387590</uniqueID>
    <date>12/21/2005</date>
    <sNo>9000</sNo>
    <sID>929</sID>
    <Pi>4.0000</Pi>
    <sName>Test Test</sName>
    <sRName>MAN</sRName>
    <sRNameL>KKL</sRNameL>
    <Category>4</Category>
    <sInterNo />
    <sInterR>0</sInterR>
  </Entry>
  <RecNum>
    <TotRec>4</TotRec>
  </RecNum>
</Reports>

Here is the XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"

doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<xsl:key name="Reports" match="Entry" use="Category" />
<xsl:template match="/">
       <style type="text/css">
BODY
{
    margin-left: 0;
    margin-bottom: 0;
    margin-right: 0;
    FONT-SIZE: 14px;
    FONT-FAMILY: Arial, Helvetica, sans-serif
}
caption
{
  text-align: left;
  font-weight: bold;
  font-size: 14px;
  FONT-FAMILY: Arial, Helvetica, sans-serif
}
        </style>
           <xsl:apply-templates select="Reports/Entry[not(sRNameL = preceding-sibling::Entry/sRNameL)]" mode="sRNameL"/>
</xsl:template>
<xsl:template match="Entry" mode="sRNameL">
    <TABLE width="600" style='width:6.25in;mso-cellspacing:.7pt;margin-left:.5in;mso-padding-alt:1.5pt 1.5pt 1.5pt 1.5pt'

border="1" cellspacing="1" cellpadding="0">
        <TR>
          <TD colspan="3" align="middle"><b><xsl:apply-templates select="sRNameL"/> Report

<xsl:value-of select="//Reports/Entry/date"/></b></TD>
        </TR>
        <TR>
          <TD><b>Total:</b></TD>
          <TD align="right"><xsl:value-of select="//Reports/RecNum/TotRec"/></TD>
          <TD align="right"><xsl:value-of select="format-number(sum(//Reports/Entry/Pi),'$###0.00')"/></TD>
        </TR>
        <xsl:if test="../Entry[sRNameL = current()/sRNameL and Category = current()/Category]">
            <xsl:variable name="count" select="count(uniqueID)"/>
        </xsl:if>
        <xsl:for-each select="../Entry[sRNameL = not(Category = preceding-sibling::Entry[state =

current()/sRNameL]/Category)]">
            <xsl:if test="Category[not(. = following::Category)]">
                <TR>
                <TD><b>Total <xsl:apply-templates select="Category"/>:</b></TD>
                <TD align="right"></TD>
                <TD align="right"><xsl:value-of select="format-number(sum(Pi),'$###0.00')" />
                </TD>
                </TR>
            </xsl:if>
        </xsl:for-each>
    </TABLE>
    <br>#160;</br>
    <xsl:apply-templates select="../Entry[sRNameL = current()/sRNameL and not(Category = preceding-sibling::Entry[state =

current()/sRNameL]/Category)]" mode="Category"/>
  </xsl:template>
  <xsl:template match="Entry" mode="Category">
    <dd>
      <xsl:if test="Category[not(. = following::Category)]">
      <table border="1" width="600" cellspacing="1" cellpadding="2">
        <caption>
          <center><xsl:apply-templates select="Category"/></center>
        </caption>
        <thead>
          <tr>
            <TD align="middle"><B>ID</B></TD>
            <TD align="middle"><B>KKL</B></TD>
            <TD align="middle"><B>Name</B></TD>
            <TD align="middle"><B>Pi Amount</B></TD>
            <TD align="middle"><B>Name</B></TD>
            <TD align="middle"><B>Add</B></TD>
          </tr>
        </thead>
        <tbody>
          <xsl:for-each select="../Entry[sRNameL = current()/sRNameL and Category = current()/Category]">
            <tr>
                    <TD align="middle"><xsl:text> </xsl:text><xsl:value-of

select="uniqueID"/><xsl:text></xsl:text></TD>
                    <TD align="middle"><xsl:text> </xsl:text><xsl:value-of

select="sID"/><xsl:text></xsl:text></TD>
                    <TD align="middle"><xsl:text> </xsl:text><xsl:value-of

select="sRName"/><xsl:text></xsl:text></TD>
                    <TD align="right"><xsl:text> </xsl:text><xsl:value-of

select="format-number(Pi,'$###0.00')"/><xsl:text></xsl:text></TD>
                    <TD align="middle"><xsl:text> </xsl:text><xsl:value-of

select="sName"/><xsl:text></xsl:text></TD>
                    <TD align="middle"><xsl:text> </xsl:text><xsl:value-of

select="sName"/><xsl:text></xsl:text></TD>
            </tr>
                    <TR>
                    <xsl:variable name="sInterNo" select="sInterNo" />
                    <xsl:choose>
                    <xsl:when test="sInterNo!=''">
                        <TD colspan="2" align="right"><B>INTER NO:</B></TD>
                        <TD><xsl:value-of select="$sInterNo" /></TD>
                    </xsl:when>
                    </xsl:choose>
                    <xsl:variable name="sInterR" select="sInterR" />
                    <xsl:choose>
                    <xsl:when test="sInterR!='0'">
                        <TD><B>INTER R:</B></TD>
                        <TD><xsl:apply-templates select="$sInterR"/></TD>
                    </xsl:when>
                    </xsl:choose>
                    </TR>
          </xsl:for-each>
        </tbody>
      </table>
      </xsl:if>
    </dd>
  </xsl:template>

<xsl:template name="ShowTransfers">
    <xsl:param name="transfers" />
        <xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>
        <xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
        <xsl:for-each select="//Entry">
        <TR>
            <TD bgcolor="#eee3e1"><B>TYPE OF CATEGORY:</B></TD>
            <TD bgcolor="#eee3e1"><xsl:apply-templates select='Category'/></TD>
        </TR>
        <TR><TD COLSPAN="2">
            <TABLE width="100%" border="0" cellspacing="1" cellpadding="2">
            <TR>
                <TD><B>ID</B></TD>
                <TD><B>KKL</B></TD>
                <TD><B>Name</B></TD>
                <TD><B>Pi Amount</B></TD>
                <TD><B>Name</B></TD>
                <TD><B>Add</B></TD>
            </TR>
                <xsl:variable name="vuniqueID"><xsl:value-of select="uniqueID" /></xsl:variable>
                <xsl:variable name="alltransfers" select="//Reports[uniqueID=$vuniqueID]" />
                <xsl:for-each select="$alltransfers">
                    <TR>
                    <TD><xsl:text> </xsl:text><xsl:value-of select="uniqueID"/><xsl:text></xsl:text></TD>
                    <TD><xsl:text> </xsl:text><xsl:value-of select="sID"/><xsl:text></xsl:text></TD>
                    <TD><xsl:text> </xsl:text><xsl:value-of

select="translate(sRName,$lcletters,$ucletters)"/><xsl:text></xsl:text></TD>
                    <TD><xsl:text> </xsl:text><xsl:value-of

select="format-number(Pi,'$###0.00')"/><xsl:text></xsl:text></TD>
                    <TD><xsl:text> </xsl:text><xsl:value-of

select="translate(sName,$lcletters,$ucletters)"/><xsl:text></xsl:text></TD>
                    <TD><xsl:text> </xsl:text><xsl:value-of

select="translate(sName,$lcletters,$ucletters)"/><xsl:text></xsl:text></TD>
                    </TR>
                    <TR>
                    <xsl:variable name="sInterNo" select="sInterNo" />
                    <xsl:choose>
                    <xsl:when test="sInterNo!=''">
                        <TD colspan="2" align="right"><B>INTER NO:</B></TD>
                        <TD><xsl:value-of select="$sInterNo" /></TD>
                    </xsl:when>
                    </xsl:choose>
                    <xsl:variable name="sInterR" select="sInterR" />
                    <xsl:choose>
                    <xsl:when test="sInterR!='0'">
                        <TD><B>INTER R:</B></TD>
                        <TD><xsl:apply-templates select="$sInterR"/></TD>
                    </xsl:when>
                    </xsl:choose>
                    </TR>
                </xsl:for-each>
    </TABLE>
    </TD></TR>
    </xsl:for-each>
</xsl:template>
<xsl:template match="Category">
    <xsl:variable name="CategoryVar" select="." />
    <xsl:choose>
    <xsl:when test="$CategoryVar='1'">
            A
    </xsl:when>
    </xsl:choose>
    <xsl:choose>
    <xsl:when test="$CategoryVar='2'">
            AB
    </xsl:when>
    </xsl:choose>
    <xsl:choose>
    <xsl:when test="$CategoryVar='3'">
            DDD
    </xsl:when>
    </xsl:choose>
    <xsl:choose>
    <xsl:when test="$CategoryVar='4'">
            ABC
    </xsl:when>
    </xsl:choose>
</xsl:template>
<xsl:template match="sInterR">
    <xsl:variable name="sInterRVar" select="." />
    <xsl:choose>
    <xsl:when test="$sInterRVar='1'">
            SND
    </xsl:when>
    </xsl:choose>
    <xsl:choose>
    <xsl:when test="$sInterRVar='2'">
            IPN
    </xsl:when>
    </xsl:choose>
</xsl:template>
</xsl:stylesheet>

does anyone knows the answer to this? try saving my xml as test.xml and the xsl as test.xsl and add this in the xml file, <?xml-stylesheet href="test.xsl" type="text/xsl"?> and u will see the report rendered and the missing information for the total count and total Pi amount under each category.

i.e. KKL Facility Report 12/21/2005
Total: 4 $11.00 (4 is the total number of records)
Total A: ? (? is the number of records under this category) $2.00 (this amount is wrong, it should be the total for this category)
Total AB: ? (? is the number of records under this category) $2.00 (this amount is wrong, it should be the total for this category)
Total ABC: ? (? is the number of records under this category) $4.00 (this amount is wrong, it should be the total for this category)

the rest of the report is correct. Thanks a lot to whoever can help me with this, i am driving nuts finding a solution.





Similar Threads
Thread Thread Starter Forum Replies Last Post
urgent deb_kareng ASP.NET 2.0 Professional 1 August 13th, 2007 07:29 AM
it's urgent deb_kareng ASP.NET 2.0 Professional 3 August 7th, 2007 07:40 AM
urgent help yash_coolbuddy_forindia BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 May 7th, 2007 08:40 AM
urgent???????????? nsr35 Beginning VB 6 1 October 3rd, 2005 10:57 AM
urgent ??????????????? nsr35 Pro VB Databases 0 October 3rd, 2005 04:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.