XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 10th, 2004, 09:45 AM
RRG RRG is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 11 RRG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Urgent please!XSLT Output:Queries


<Customer Code="001" Name="Arup Ray" City="Kolkata">
<!--<Account Code="001"/>
<Account Code="002"/>-->

<SSN>001-44-8888</SSN>
<Gender>Male</Gender>
<State>WB</State>
<Country>India</Country>
<AccBal>35000.00</AccBal>
<Dep>250.00</Dep>
<Dep>375.00</Dep>
<Wdl>50.00</Wdl>
<Wdl>25.00</Wdl>
<localCurrency>INR</localCurrency>
<exchangeRate>45</exchangeRate>

</Customer>


<Product ID="001" Name="Checking">


<MinBal>500.00</MinBal>
<Int>.20</Int>
<Fees>2.00</Fees>


</Product>


<Customer Code="003" Name="Paula Smith" City="Boston">
<!-- <Account Code="003"/>
<Account Code="004"/>-->

<SSN>001-22-1111</SSN>
<Gender>Female</Gender>
<State>MA</State>
<Country>USA</Country>
<AccBal>15000.00</AccBal>
<Dep>100.00</Dep>
<Dep>50.00</Dep>
<Wdl>20.00</Wdl>
<Wdl>40.00</Wdl>

</Customer>


<Product ID="002" Name="Savings">



<MinBal>5000.00</MinBal>
<Int>.20</Int>
<Fees>3.00</Fees>

</Product>

<Customer Code="002" Name="Robin Kidman" City="Cambridge">
<!--<Account Code="002"/>
<Account Code="001"/>--> <!--Customer can have 0 or more accounts-->
<SSN>001-55-7777</SSN>
<Gender>Female</Gender>
<State>BH</State>
<Country>UK</Country>
<AccBal>8000.00</AccBal>
<Dep>250.00</Dep>
<Wdl>50.00</Wdl>
<localCurrency>GBP</localCurrency>
<exchangeRate>1.5</exchangeRate>


</Customer>

<Product ID="003" Name="CD">



<MinBal>10000.00</MinBal>
<Int>.20</Int>
<Fees>4.00</Fees>


</Product>

<Customer Code="002" Name="Chris Shaw" City="Atlanta" >
<!--<Account Code="002"/>
<Account Code="003/> -->

<SSN>001-11-5234</SSN>
<Gender>Male</Gender>
<State>GA</State>
<Country>USA</Country>
<AccBal>40000.00</AccBal>
<Dep>300.00</Dep>
<Wdl>100.00</Wdl>

</Customer>


<Product ID="004" Name="IRA">



<MinBal>20000.00</MinBal>
<Int>.20</Int>
<Fees>5.00</Fees>


</Product>


</Bank>
---------------------
How do I extract using XSL aply-tempalte/template -match and other xpath expr :
1. All customers outside USA
2. Calculate Total Dep and total Wdl
3. Display customers whose AccBal is > MinBal
4. Maybe extract all Male custoemrs
5.Multiply exchangeaRate * localCurrency

I shall be ever grateful dfor any help with this ,please!

Reply With Quote
  #2  
Old August 12th, 2004, 05:39 PM
tsprings tsprings is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Seattle, WA
Posts: 55 tsprings User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 6
Hello RRG.

In the interest of time I modified your xml a bit:

Dev.xml
Code:
<?xml
 version="1.0"
 encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="dev.xsl"?>
<CustProd>
  <Customers>
    <Customer
     Code="001"
     Name="Arup Ray"
     City="Kolkata">
      <Accounts>
        <Account
         Code="001" />
        <Account
         Code="002" />
      </Accounts>
      <SSN>001-44-8888</SSN>
      <Gender>Male</Gender>
      <State>WB</State>
      <Country>India</Country>
      <AccBal>35000.00</AccBal>
      <Deps>
      <Dep>250.00</Dep>
      <Dep>375.00</Dep>
      </Deps>
      <Wdls>
      <Wdl>50.00</Wdl>
      <Wdl>25.00</Wdl>
      </Wdls>
      <localCurrency>INR</localCurrency>
      <exchangeRate>45</exchangeRate>
    </Customer>
    <Customer
     Code="003"
     Name="Paula Smith"
     City="Boston">
      <Accounts>
        <Account
         Code="003" />
        <Account
         Code="004" />
      </Accounts>
      <SSN>001-22-1111</SSN>
      <Gender>Female</Gender>
      <State>MA</State>
      <Country>USA</Country>
      <AccBal>15000.00</AccBal>
      <Deps>
      <Dep>100.00</Dep>
      <Dep>50.00</Dep>
      </Deps>
      <Wdls>
      <Wdl>20.00</Wdl>
      <Wdl>40.00</Wdl>
      </Wdls>
    </Customer>
    <Customer
     Code="002"
     Name="Robin Kidman"
     City="Cambridge">
      <Accounts>
        <Account
         Code="001" />
        <Account
         Code="002" />
      </Accounts>
      <SSN>001-55-7777</SSN>
      <Gender>Female</Gender>
      <State>BH</State>
      <Country>UK</Country>
      <AccBal>8000.00</AccBal>
      <Deps>
      <Dep>250.00</Dep>
      </Deps>
      <Wdls>
      <Wdl>50.00</Wdl>
      </Wdls>
      <localCurrency>GBP</localCurrency>
      <exchangeRate>1.5</exchangeRate>
    </Customer>
    <Customer
     Code="002"
     Name="Chris Shaw"
     City="Atlanta">
      <Accounts>
        <Account
         Code="003" />
        <Account
         Code="002" />
      </Accounts>
      <SSN>001-11-5234</SSN>
      <Gender>Male</Gender>
      <State>GA</State>
      <Country>USA</Country>
      <AccBal>40000.00</AccBal>
      <Deps>
      <Dep>300.00</Dep>
      </Deps>
      <Wdls>
      <Wdl>100.00</Wdl>
      </Wdls>
    </Customer>
  </Customers>
  <Products>
    <Product
     ID="001"
     Name="Checking">
      <MinBal>500.00</MinBal>
      <Int>.20</Int>
      <Fees>2.00</Fees>
    </Product>
    <Product
     ID="002"
     Name="Savings">
      <MinBal>5000.00</MinBal>
      <Int>.20</Int>
      <Fees>3.00</Fees>
    </Product>
    <Product
     ID="003"
     Name="CD">
      <MinBal>10000.00</MinBal>
      <Int>.20</Int>
      <Fees>4.00</Fees>
    </Product>
    <Product
     ID="004"
     Name="IRA">
      <MinBal>20000.00</MinBal>
      <Int>.20</Int>
      <Fees>5.00</Fees>
    </Product>
  </Products>
</CustProd>


Here is the corresponding xsl.

Dev.xsl
Code:
<?xml
 version="1.0"
 encoding="iso-8859-1"?>
<xsl:stylesheet
 version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template
   match="/">
    <html>
      <body>
        <h3>1. All customers outside USA</h3>
        <xsl:for-each
         select="CustProd/Customers/Customer">          
          <xsl:if test="Country != 'USA'">
          <xsl:value-of
           select="@Name" /><br/>
           </xsl:if>          
        </xsl:for-each>
        <h3>2. Calculate Total Dep and total Wdl</h3>
        <xsl:for-each
         select="CustProd/Customers">   
          Total Dep: <xsl:value-of select="format-number(sum(Customer/Deps/Dep), '$###,###.00')"/><br />
          Total Wdl: <xsl:value-of select="format-number(sum(Customer/Wdls/Wdl), '$###,###.00')"/><br />
        </xsl:for-each>
        <h3>3. Display customers whose AccBal is > MinBal</h3>
        <h5>Didn't have the time to play with this any more...  Thought you might want to see how far I got</h5>
        <xsl:for-each
         select="CustProd/Customers/Customer">          
          <xsl:value-of
           select="@Name" />,
           <ul> 
                 <li><b>Account Balance:</b>  <xsl:value-of select="format-number(AccBal, '$###,###.00')" /></li>
                 <li><b>Account Type(s): </b>
                 <ul>
           <xsl:for-each
         select="Accounts/Account">             
         <xsl:variable name="currentCode" select='@Code' />
         <xsl:variable name="sumCodes" select='//Products/Product[@ID=$currentCode]/MinBal' />
         <li><xsl:value-of select="$currentCode" /> (Min: <xsl:value-of select="format-number($sumCodes, '$###,###.00')"/>)</li>
           </xsl:for-each>
           </ul>
           </li>
          </ul><br />
        </xsl:for-each>
        <h3>4. Maybe extract all Male custoemrs</h3>
        <xsl:for-each
         select="CustProd/Customers/Customer">          
          <xsl:if test="Gender = 'Male'">
          <xsl:value-of
           select="@Name" /><br/>
           </xsl:if>          
        </xsl:for-each>
        <h3>5. Multiply exchangeaRate * localCurrency</h3>
        <h5>Wasn't sure what exactly you wanted here, so I multiplied exchangeRate by the AcclBalance instead</h5>
        <xsl:for-each
         select="CustProd/Customers/Customer">          
          <xsl:if test="exchangeRate != ''">
          <xsl:value-of
           select="@Name" />: <xsl:value-of
           select="format-number(exchangeRate * AccBal, '$###,###.00')" /><br/>
           </xsl:if>          
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>


Hopefully that will give you something to start with.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Urgent please!XSLT Output:Queries


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT