|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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??? |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Quote:
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! |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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 ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Position() problem!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|