 |
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 7th, 2004, 04:08 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 7th, 2004, 04:32 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
OK... I've added "[1]" to page[ ../value=''CYL2'' ][1] as the expression initially returns a nodeset, same result, tho
thanks
|
|

January 8th, 2004, 08:44 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
You've forgotten that the < symbol can't be used, it has to be the entity < instead (the ampersand will disappear from the forum post but it should read as ampersand-l-t-;)
|
|

January 8th, 2004, 08:46 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hey, looks like the disappearing ampersands have been fixed. &&&&&& gr8 :D &&&&&&&&
|
|

January 8th, 2004, 09:03 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

January 8th, 2004, 09:36 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 8th, 2004, 10:46 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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
|
|

January 8th, 2004, 10:56 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 8th, 2004, 11:26 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
If you can do that your context element (i.e. the node that variable doc points to must be the document element).
--
Joe
|
|

January 8th, 2004, 12:17 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks again for your help, Joe
Cheers
David
|
|
 |