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 9th, 2004, 05:12 AM
1ei1a 1ei1a is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 32 1ei1a User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 28 m 13 sec
Reputation Power: 5
Angry Position() problem!!

Hi,

I have an xml document as follows:

<my:InsideViewList>
<my:InsideView>
<my:Title>LATEST news article</my:Title>
<my:StandFirst>LATEST news standfirst</my:StandFirst>
<my:XMLDoc>blah</my:XMLDoc>
</my:InsideView>
<my:InsideView>
<my:Title>story four</my:Title>
<my:StandFirst>standfirst four</my:StandFirst>
<my:XMLDoc>blah</my:XMLDoc>
</my:InsideView>

<my:InsideView>
<my:Title>story three</my:Title>
<my:StandFirst>standfirst three</my:StandFirst>
<my:XMLDoc>blah</my:XMLDoc>
</my:InsideView>
<my:InsideView>
<my:Title>story two</my:Title>
<my:StandFirst>standfirst two</my:StandFirst>
<my:XMLDoc>blah</my:XMLDoc>
</my:InsideView>
<my:InsideView>
<my:Title>story one</my:Title>
<my:StandFirst>standfirst one</my:StandFirst>
<my:XMLDoc>blah</my:XMLDoc>
</my:InsideView>
</my:InsideViewList>

I want to retrieve the SECOND news article (i.e: "story four").

I have tried: my:InsideViewList/my:InsideView/my:Title[position() = 2]. But this is not working. What am I doing wrong???

Reply With Quote
  #2  
Old August 9th, 2004, 06:21 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
If I understand well, you're looking to get the title from the second news item, so you have to do this :

my:InsideViewList/my:InsideView[position() = 2]/my:Title

In your example, you were requesting the second title, which doesn't exist.

Grtz

Reply With Quote
  #3  
Old August 9th, 2004, 06:35 AM
1ei1a 1ei1a is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 32 1ei1a User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 28 m 13 sec
Reputation Power: 5
Red face

Quote:
Originally Posted by kid23
If I understand well, you're looking to get the title from the second news item, so you have to do this :

my:InsideViewList/my:InsideView[position() = 2]/my:Title

In your example, you were requesting the second title, which doesn't exist.

Grtz


Kid23, you're a genius! Thanks for your help on this one. Spent many hours trying to figure this out. Your answer also highlights a fundamental concept I've been missing all these weeks: where tp place my functions in relation to nodes. Should spend more time on understanding the basic concepts I think!

Reply With Quote
  #4  
Old August 10th, 2004, 01:20 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
kindly help me before 8/12/04

In order for XSL to work against the XML file, in the XML files do we NEED to uncomment the
referencing line to the XSD i.e. uncomment this ?

xsi:schemaLocation='http://xml.XMLCourse.edu/targetNS HW3Schema.xsd

also, do you know how to extract using XSLT expression the alternate elements such as Customer [with child elements] and Product [with child elements] under the root called Bank?
here is my XMl file:
<Bank xmlns='http://xml.XMLCourse.edu/targetNS'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<!--xsi:schemaLocation='http://xml.XMLCourse.edu/targetNS HW3Schema.xsd'>-->


<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>







Thank you.

Reply With Quote
  #5  
Old August 10th, 2004, 01:21 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
To KID23

In order for XSL to work against the XML file, in the XML files do we NEED to uncomment the
referencing line to the XSD i.e. uncomment this ?

xsi:schemaLocation='http://xml.XMLCourse.edu/targetNS HW3Schema.xsd

also, do you know how to extract using XSLT expression the alternate elements such as Customer [with child elements] and Product [with child elements] under the root called Bank?
here is my XMl file:
<Bank xmlns='http://xml.XMLCourse.edu/targetNS'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<!--xsi:schemaLocation='http://xml.XMLCourse.edu/targetNS HW3Schema.xsd'>-->


<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>







Thank you.

Reply With Quote
  #6  
Old August 10th, 2004, 05:22 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
To Leila: No problem really, helping out each other is the purpose of boards like this one

To RRG:
I have limited experience with XSD, but to my knowledge, XSD, like DTD only concern document content validation, and therefore do not impact on your xsl reference.

I'm not sure either what you're trying to do in XSL, you say you want to extract elements, but "extracting" elements is not exactly what xsl does.. although it might just be a terminology issue.

What you do with XSL is to define templates that are able to "process" xml tags. A very brief example:

XML:
Code:
<RootNode>
  <ChildNode>Value 1</ChildNode>
  <ChildNode>Value 1</ChildNode>
</RootNode>


XSL:
Code:
<xsl:template match="RootNode">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="ChildNode">
  <xsl:value-of select="text()" />
</xsl:template>


In this small example, I've written two templates in xsl, which will be "called" whenever nodes with a matching name is found is xml. Within the RootNode template, I use the xsl rule "apply-templates" which means : apply the appropriate templates for whatever content is found under <RootNode>.

I advise you to come back to the basics of XSLT, this site will help:

http://www.w3schools.com/

Hope this helps

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Position() problem!!


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