Subject: Nested XPath Expression
Posted By: sonicDace Post Date: 1/7/2004 3:08:12 PM
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
Reply By: sonicDace Reply Date: 1/7/2004 3:32:59 PM
OK... I've added "[1]" to page[ ../value=''CYL2'' ][1] as the expression initially returns a nodeset, same result, tho

thanks
Reply By: pgtips Reply Date: 1/8/2004 7:44:54 AM
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-;)
Reply By: pgtips Reply Date: 1/8/2004 7:46:30 AM
Hey, looks like the disappearing ampersands have been fixed. &&&&&& gr8 &&&&&&&&
Reply By: joefawcett Reply Date: 1/8/2004 8:03:45 AM
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)
Reply By: sonicDace Reply Date: 1/8/2004 8:36:54 AM
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
Reply By: joefawcett Reply Date: 1/8/2004 9:46:28 AM
Try this:

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

OR

/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
Reply By: sonicDace Reply Date: 1/8/2004 9:56:42 AM
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
Reply By: joefawcett Reply Date: 1/8/2004 10:26:02 AM
If you can do that your context element (i.e. the node that variable doc points to must be the document element).

--

Joe
Reply By: sonicDace Reply Date: 1/8/2004 11:17:08 AM
thanks again for your help, Joe

Cheers

David

Go to topic 8335

Return to index page 973
Return to index page 972
Return to index page 971
Return to index page 970
Return to index page 969
Return to index page 968
Return to index page 967
Return to index page 966
Return to index page 965
Return to index page 964