|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
TO:kid23 or anybody: pls help me!XSL and Namespace alias:
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 Do you know if using a Namespacelike this might help...? But in the schema & xml do I need to declare all elements with the NS alias? How do I create for-loop or International customers, etc with alias ns? Kindly help me...- - <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="http://xml.XMLCourse.edu/targetNS"> <xsl utput method="html" /> - <xsl:template match="/"> - <html> - <body> <h3>Display International Customers</h3> - <table border="1"> - <tr bgcolor="#9acd32"> <th>Country</th> <th>USD Balance</th> </tr> - <tr> - <td> <xsl:apply-templates select="ns:Bank/ns:Customer" /> </td> </tr> </table> </body> </html> </xsl:template> - <xsl:template match="ns:Customer"> - <tr> - <td> <xsl:value-of select="ns:Country" /> </td> - <td> <xsl:value-of select="ns:AccBal" /> </td> </tr> </xsl:template> </xsl:stylesheet> I shall be ever grateful dfor any help with this ,please! <Bank> <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> ********* |
|
#2
|
|||
|
|||
|
The thing you have to focus on to solve this problem is XPATH, and only xpath. Forget about schema and namespaces at this level.
Judging from your code, you're not far from a part of the solution. I obviously can't give you the full answer, but at least good hints to reach it. For instance, when you ask in #1 how to select customers outside USA, this can be done by turning your apply-templates into : <xsl:apply-templates select="//Customer[Country != 'USA']" /> This will only select the Customer nodes having a Country child node with a value different than USA. As I said, learn XPath, or even learn SQL which is a database query language. If you understand SQL, going to XPath is only a matter of learning a new syntax. This site will help: http://www.w3schools.com/xpath/default.asp For things like totals, you should put display them with: <xsl:value-of select="sum(//wdl)" /> or put them into an xsl:variable if you have to. Work on it, and if you get stuck on a specific issue, let me know, I'll be glad to help ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > TO:kid23 or anybody: pls help me!XSL and Namespace alias: |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|