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 June 17th, 2004, 09:10 AM
kid23 kid23 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 62 kid23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
XPath with variables

Hi,

I'd like to make a selection of external data into XSLT, therefore, I'm using a syntax like:

<xsl:apply-templates select="document($MembersDB)//Member[Nick=$NickName]/*[name()=$FieldName]" />

This is working fine for the moment, assuming that variables have a valid content, it will select (in the file $MembersDB) the Members whose Nick = $NickName, and return the name of a given child tag.

What I'd like to do is to have this piece of code a bit more generic, and not be dependent on "Member" or "Nick"..

so instead of:

<xsl:apply-templates select="document($MembersDB)//Member/*" />

I could use something like this:

<xsl:apply-templates select="document($MembersDB)//$tag/*" />

where $tag is set using xsl:variable.

Is it possible ? Is it simply a syntax error (I tried putting $tag between curly braces too, but that didn't help) ?

Thx in advance.

Reply With Quote
  #2  
Old August 10th, 2004, 12:09 PM
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
NAMESPACE ALIAS & XSLT: PLS HELP ME aSAP :(:(

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 below 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">
<xslutput 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>



*********

Reply With Quote
  #3  
Old August 10th, 2004, 08:13 PM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 305 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 7 h 17 m 54 sec
Reputation Power: 7
XPath variables represent values, they are not to quote
Michael Kay "macros that represent parts of an expression."

What you want to do is not possible in XSLT 1.0. A variable cannot be used after "/" or "//".

There are workarounds and some XSLT processors support the syntax as an extension.

Do a Web search on "XPath dynamic variable" for further information.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XPath with variables


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 3 hosted by Hostway
Stay green...Green IT