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 November 12th, 2007, 11:01 PM
Authorized User
 
Join Date: Nov 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi All,
       I got it..,

Only Based on the Date;
<xsl:value-of select="sum($invoices/*/Invoice[starts-with(Date, current()/Month)]/Qty)"/>

Based on Specific Date,Country and Product;
<xsl:value-of select="sum($invoices/*/Invoice[starts-with(Date, current()/Month['2007-05']) and Country='India' and Product='HH']/Qty)"/>

 I think the bug is, we missed out the $invoices/*/Invoice[...
Thank you Mr.Joe to denote that.

Once again, Thank you All to helped me out to solve this problem.



viv
 
Old November 13th, 2007, 06:01 AM
Authorized User
 
Join Date: Nov 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

   I'm passing param from javascript to xsl. The params are Country, Product and Month.The values are passing and It's giving the sum(InvoiceQty) as shown below;

Condition[Month=2007-05 and Country=India and Product=HH]
2007-09 HH India 0 100
2007-07 AA India 0 200
2007-02 BB Australia 0 150
2007-05 HH Australia 15 300
2007-07 CC India 0 250
2007-05 HH India 15 250

---> I dont know why it's displaying also for "Australia" which matches the same month and product but different Country.Suppose to be "0".
---> Also, I want to display only one row which is,
2007-05 HH India 15 250 - which match all the condition.
I have given different tries to eliminate other rows. But no use
help me pls...,

Below is my code;

function joinXml()
{
            // Load XML
            var xml = new ActiveXObject("Microsoft.XMLDOM")
            xml.async = false
            xml.load("Inventry.xml")
            // Load XSL
            var xsl = new ActiveXObject("Microsoft.XMLDOM")
            var xslt = new ActiveXObject("Msxml2.XSLTemplate.3.0");
            var xsldoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0" );

            xsldoc.async = false;
            xsldoc.load('Inventry.xsl');
            xslt.stylesheet = xsldoc;

            var xslproc = xslt.createProcessor();
            xslproc.input = xml;
            xslproc.addParameter("ctry", "India");
            xslproc.addParameter("iMon", "2007-05");
            xslproc.addParameter("prdt", "HH");
            xslproc.transform();
            document.write(xslproc.output)
}

Xsl:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:fx="#fx-functions" exclude-result-prefixes="msxsl fx">
    <xsl:output method="html" version="4.0" indent="yes" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
  <xsl:param name="ctry"/>
  <xsl:param name="prdt"/>
  <xsl:param name="iMon"/>

  <xsl:variable name="invoices" select="document('invoice.xml')"/>

  <xsl:template match="Inventry" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <table border="1">
        <tr>
          <td>
            <xsl:copy-of select="Month"/>
          </td>
          <td>
            <xsl:copy-of select="Product"/>
          </td>
          <td>
            <xsl:copy-of select="Country"/>
            </td>
             <td>
            <SumQty>
              <xsl:copy-of select="sum($invoices/*/Invoice[Country=$ctry and Product=$prdt and starts-with($iMon, current()/Month)]/Qty)"/>
            </SumQty>
          </td>
             <td>
               <xsl:copy-of select="Qty"/>
          </td>
    </tr>
      </table>
    </xsl:template>
</xsl:stylesheet>

I tried like this;

  <xsl:template match="Inventry" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <table border="1">
        <tr>
          <td>
            <xsl:copy-of select="Month[starts-with($iMon,current()/Month)]"/>
          </td>
          <td>
            <xsl:copy-of select="Product[starts-with($prdt,current()/Product)]"/>
          </td>
          <td>
            <xsl:copy-of select="Country[starts-with($ctry,current()/Country)]"/>
            </td>
             <td>
            <SumQty>
              <xsl:value-of select="sum($invoices/*/Invoice[starts-with(Date, current()/Month[$iMon]) and Country=$ctry and Product=$prdt]/InvQty)"/>
            </SumQty>
          </td>
             <td>
               <xsl:copy-of select="Qty"/>
          </td>
    </tr>
      </table>
    </xsl:template>

Thank you

viv
 
Old November 13th, 2007, 06:07 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Change

<xsl:template match="Inventory">

to

<xsl:template match="Inventory[Country=$ctry and Month=$iMon and Product=$prdt]">


/- Sam Judson : Wrox Technical Editor -/
 
Old November 13th, 2007, 06:28 AM
Authorized User
 
Join Date: Nov 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 Yes, I have tried b4, but i got an error "Variables cannot be used within this expression".
Is thr any other way??


viv
 
Old November 13th, 2007, 06:31 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

In that case you'll have to do this:

<xsl:template match="dataroot">
  <xsl:apply-templates select="Inventory[Country=$ctry and Month=$iMon and Product=$prdt]">
</xsl:template>

/- Sam Judson : Wrox Technical Editor -/
 
Old November 13th, 2007, 06:43 AM
Authorized User
 
Join Date: Nov 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Got it, Thank you Sam!

viv
 
Old August 23rd, 2008, 02:50 PM
Registered User
 
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Sam! Your post was a lifesaver.






Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript and XMLDOM kirthi97 XML 4 June 27th, 2006 02:22 AM
Pogramming the XmlDOM in C# sencee C# 5 March 10th, 2006 11:09 AM
access sub nodes using XMLDOM lian_a Classic ASP XML 2 January 19th, 2005 09:43 PM
XMLDOM problem braindog_43 Javascript How-To 2 January 16th, 2005 01:54 PM
XMLDOM problem braindog_43 XML 2 January 16th, 2005 01:38 PM





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