Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 7th, 2004, 03:08 PM
Authorized User
 
Join Date: Nov 2003
Location: Hollywood, Fl, USA.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default Nested XPath Expression

I'm having a little trouble with the following expression:

separatorNodes = doc.selectNodes('barcode[ (page) <= (page[ ../value=''CYL2'' ]) ]');

I am trying to select all nodes whos page number are less than the page number whos sibling value = 'CYL2'. Problem is, it's selecting only the one whos page number is equal to that, and ignores the "less than" part.


any suggestions?

Thanks

thanks
__________________
thanks
  #2 (permalink)  
Old January 7th, 2004, 03:32 PM
Authorized User
 
Join Date: Nov 2003
Location: Hollywood, Fl, USA.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

OK... I've added "[1]" to page[ ../value=''CYL2'' ][1] as the expression initially returns a nodeset, same result, tho

thanks
  #3 (permalink)  
Old January 8th, 2004, 07:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You've forgotten that the < symbol can't be used, it has to be the entity &lt; instead (the ampersand will disappear from the forum post but it should read as ampersand-l-t-;)
  #4 (permalink)  
Old January 8th, 2004, 07:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey, looks like the disappearing ampersands have been fixed. &&&&&& gr8 :D &&&&&&&&
  #5 (permalink)  
Old January 8th, 2004, 08:03 AM
joefawcett's Avatar
Wrox Author
Points: 9,716, Level: 42
Points: 9,716, Level: 42 Points: 9,716, Level: 42 Points: 9,716, Level: 42
Activity: 8%
Activity: 8% Activity: 8% Activity: 8%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,067
Thanks: 1
Thanked 37 Times in 36 Posts
Default

pgtips

I don't think that is the problem as sonicDace stated he was retrieving results, just not the right ones.

sonicDace

Can you show the relevant source xml as I'm having difficulty picturing what you need?

Joe (MVP - xml)
  #6 (permalink)  
Old January 8th, 2004, 08:36 AM
Authorized User
 
Join Date: Nov 2003
Location: Hollywood, Fl, USA.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

LOL... What was I thinking? Here you go:

 <barcode_program>
- <barcode>
  <page>1</page>
  <symbology>Code 39</symbology>
  <value>CYL1</value>
  <position>98,454</position>
  <height>102</height>
  <width>575</width>
  </barcode>
- <barcode>
  <page>1</page>
  <symbology>Code 39</symbology>
  <value>SUBJECT</value>
  <position>98,454</position>
  <height>102</height>
  <width>575</width>
  </barcode>
- <barcode>
  <page>1</page>
  <symbology>Code 39</symbology>
  <value>Organization</value>
  <position>1457,465</position>
  <height>100</height>
  <width>319</width>
  </barcode>
- <barcode>
  <page>1</page>
  <symbology>Code 39</symbology>
  <value>SUISSE</value>
  <position>1263,282</position>
  <height>104</height>
  <width>514</width>
  </barcode>
- <barcode>
  <page>1</page>
  <symbology>Interleaved 2 of 5</symbology>
  <value>keywords</value>
  <position>99,634</position>
  <height>116</height>
  <width>481</width>
  </barcode>
- <barcode>
  <page>1</page>
  <symbology>Code 39</symbology>
  <value>NAME</value>
  <position>98,274</position>
  <height>100</height>
  <width>382</width>
  </barcode>
- <barcode>
  <page>1</page>
  <symbology>Interleaved 2 of 5</symbology>
  <value>Zurich,Basel</value>
  <position>1097,641</position>
  <height>119</height>
  <width>655</width>
  </barcode>
- <barcode>
  <page>4</page>
  <symbology>Code 39</symbology>
  <value>SUBJECT</value>
  <position>96,456</position>
  <height>102</height>
  <width>575</width>
  </barcode>
- <barcode>
  <page>4</page>
  <symbology>Code 39</symbology>
  <value>Organization</value>
  <position>1456,466</position>
  <height>100</height>
  <width>319</width>
  </barcode>
- <barcode>
  <page>4</page>
  <symbology>Code 39</symbology>
  <value>FRANCE</value>
  <position>1262,285</position>
  <height>102</height>
  <width>513</width>
  </barcode>
- <barcode>
  <page>4</page>
  <symbology>Interleaved 2 of 5</symbology>
  <value>keywords</value>
  <position>97,636</position>
  <height>116</height>
  <width>481</width>
  </barcode>
- <barcode>
  <page>4</page>
  <symbology>Code 39</symbology>
  <value>NAME</value>
  <position>96,277</position>
  <height>100</height>
  <width>383</width>
  </barcode>
- <barcode>
  <page>4</page>
  <symbology>Interleaved 2 of 5</symbology>
  <value>Paris,Marseilles</value>
  <position>923,641</position>
  <height>120</height>
  <width>828</width>
  </barcode>
- <barcode>
  <page>4</page>
  <symbology>Code 39</symbology>
  <value>CYL2</value>
  <position>98,454</position>
  <height>102</height>
  <width>575</width>
  </barcode>
- <barcode>
  <page>7</page>
  <symbology>Code 39</symbology>
  <value>SUBJECT</value>
  <position>98,451</position>
  <height>101</height>
  <width>576</width>
  </barcode>
- <barcode>
  <page>7</page>
  <symbology>Code 39</symbology>
  <value>Organization</value>
  <position>1458,465</position>
  <height>100</height>
  <width>319</width>
  </barcode>
- <barcode>
  <page>7</page>
  <symbology>Code 39</symbology>
  <value>ITALIE</value>
  <position>1263,282</position>
  <height>104</height>
  <width>515</width>
  </barcode>
- <barcode>
  <page>7</page>
  <symbology>Interleaved 2 of 5</symbology>
  <value>keywords</value>
  <position>98,632</position>
  <height>116</height>
  <width>481</width>
  </barcode>
- <barcode>
  <page>7</page>
  <symbology>Code 39</symbology>
  <value>NAME</value>
  <position>97,272</position>
  <height>100</height>
  <width>383</width>
  </barcode>
- <barcode>
  <page>7</page>
  <symbology>Interleaved 2 of 5</symbology>
  <value>Rome,Milan</value>
  <position>1182,642</position>
  <height>119</height>
  <width>572</width>
  </barcode>
- <barcode>
  <page>10</page>
  <symbology>Code 39</symbology>
  <value>SUBJECT</value>
  <position>95,453</position>
  <height>103</height>
  <width>576</width>
  </barcode>
- <barcode>
  <page>10</page>
  <symbology>Code 39</symbology>
  <value>Organization</value>
  <position>1455,462</position>
  <height>101</height>
  <width>319</width>
  </barcode>
- <barcode>
  <page>10</page>
  <symbology>Code 39</symbology>
  <value>BOSNIE</value>
  <position>1261,282</position>
  <height>101</height>
  <width>513</width>
  </barcode>
- <barcode>
  <page>10</page>
  <symbology>Interleaved 2 of 5</symbology>
  <value>keywords</value>
  <position>96,634</position>
  <height>116</height>
  <width>482</width>
  </barcode>
- <barcode>
  <page>10</page>
  <symbology>Interleaved 2 of 5</symbology>
  <value>Sarajevo,Mostar</value>
  <position>966,639</position>
  <height>119</height>
  <width>785</width>
  </barcode>
- <barcode>
  <page>10</page>
  <symbology>Code 39</symbology>
  <value>NAME</value>
  <position>94,274</position>
  <height>100</height>
  <width>383</width>
  </barcode>
  </barcode_program>


Problem is, it's only retreiving the node:

- <barcode>
  <page>4</page>
  <symbology>Code 39</symbology>
  <value>CYL2</value>
  <position>98,454</position>
  <height>102</height>
  <width>575</width>
  </barcode>


When it should retreive that node and all nodes with a <page/> less than the <page/> specified on that node, which is in this case "4".





thanks
  #7 (permalink)  
Old January 8th, 2004, 09:46 AM
joefawcett's Avatar
Wrox Author
Points: 9,716, Level: 42
Points: 9,716, Level: 42 Points: 9,716, Level: 42 Points: 9,716, Level: 42
Activity: 8%
Activity: 8% Activity: 8% Activity: 8%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,067
Thanks: 1
Thanked 37 Times in 36 Posts
Default

Try this:
Code:
/barcode_program/barcode[page <= /barcode_program/barcode/page[../value[. = 'CYL2']]]
OR
Code:
/barcode_program/barcode[page <= //page[../value[. = 'CYL2']]]
You may be able to alter the part after the comparison, I don't know where you are when you call selectNodes. You don't need to escape characters when using dom, only when using XSLT. It's a requirement that serialised xml files do not contain < and other characters, it doesn't apply to files held in memory etc.

Joe (MVP - xml)

--

Joe
  #8 (permalink)  
Old January 8th, 2004, 09:56 AM
Authorized User
 
Join Date: Nov 2003
Location: Hollywood, Fl, USA.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

Joe,

Thanks!!! Both solutions worked. I even tried one of my own:

'barcode[ page <= //page[ ../value =''CYL2'' ] ]'

which worked fine too.

I do confess I'm scratching my head wondering what the logical reason for the failure was. In this case, the "//" before the page[...] did the difference. Why is that?


thanks
  #9 (permalink)  
Old January 8th, 2004, 10:26 AM
joefawcett's Avatar
Wrox Author
Points: 9,716, Level: 42
Points: 9,716, Level: 42 Points: 9,716, Level: 42 Points: 9,716, Level: 42
Activity: 8%
Activity: 8% Activity: 8% Activity: 8%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,067
Thanks: 1
Thanked 37 Times in 36 Posts
Default

If you can do that your context element (i.e. the node that variable doc points to must be the document element).

--

Joe
  #10 (permalink)  
Old January 8th, 2004, 11:17 AM
Authorized User
 
Join Date: Nov 2003
Location: Hollywood, Fl, USA.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

thanks again for your help, Joe

Cheers

David
Closed Thread


Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath 2.0 every expression stolte XSLT 5 November 24th, 2008 02:32 PM
xpath-nested expression vinod.kumbar RSS and Atom 0 July 8th, 2008 11:36 AM
XPath Expression NEO1976 XSLT 11 August 2nd, 2006 02:28 AM
nested xPath chetrity XML 5 June 8th, 2006 06:26 PM
Need help with XPATH Expression benomathew XML 1 May 9th, 2006 03:38 PM



All times are GMT -4. The time now is 01:24 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.