Jump to content

Need Help With Xpath Geting Max Value After A Query


haddadrr

Recommended Posts

Hi guys! I have turned to this forum beacuse I am tired of serching on the web, this problem is already fuzzing my brain. Well lets start from the beginning. I am building an HTML application, with javascript and xml. My XML file is as below: <cadastro> <instrumento> <diareg>2011/11/25</diareg> <id>0107006</id> <idsetor>1</idsetor> <idgrupo>7</idgrupo> <idsequencia>006</idsequencia> <nome>Escala Graduada de Aço</nome> <modelo>Mecanico</modelo> <fabricante>Stanley</fabricante> <nserie>--</nserie> <capacidademin>0.0</capacidademin> <capacidademax>600.0</capacidademax> <resolucao>0.5</resolucao> <unidade>mm</unidade> <complemento>Escala com duas graduações em milímetro e polegada</complemento> <estado>conforme</estado> <tipocalibra>ci</tipocalibra> <procedimento>IT-FLB-53-CQ-037</procedimento> <proxdiacalib>2012/8/21</proxdiacalib> <periodocalib>365</periodocalib> <ficha> <dia>2011/11/25</dia> <certificado>CQ225/11</certificado> <hiperlink>N/A</hiperlink> <diacalib>2011/8/22</diacalib> <erromin>0.0</erromin> <erromax>0.05</erromax> <erromed>0.025</erromed> <incerteza>0.01</incerteza> <situacao>calibrado</situacao> <historico>Disponível para o uso</historico> <status>Conforme</status> <valor>0</valor> </ficha> </instrumento> <instrumento> <diareg>2011/11/25</diareg> <id>0113025</id> <idsetor>1</idsetor> <idgrupo>13</idgrupo> <idsequencia>025</idsequencia> <nome>Micrômetro Externo</nome> <modelo>Mecanico</modelo> <fabricante>Mitutoyo</fabricante> <nserie>86437051</nserie> <capacidademin>0.0</capacidademin> <capacidademax>25.0</capacidademax> <resolucao>0.01</resolucao> <unidade>mm</unidade> <complemento>Micrometro para medição de canal do Zeta.</complemento> <estado>conforme</estado> <tipocalibra>ci</tipocalibra> <procedimento>IT-FLB-53-CQ-037</procedimento> <proxdiacalib>2012/1/16</proxdiacalib> <periodocalib>60</periodocalib> <ficha> <dia>2011/11/25</dia> <certificado>CQ330/11</certificado> <hiperlink>N/A</hiperlink> <diacalib>2011/11/17</diacalib> <erromin>0.1</erromin> <erromax>0.1</erromax> <erromed>0.1</erromed> <incerteza>0.01</incerteza> <situacao>calibrado</situacao> <historico>Disponível para o CQ</historico> <status>Conforme</status> <valor>0</valor> </ficha> </instrumento></cadastro> I`m using this xml file as a simple database for my application, were I control info about instruments as caliper, micrometer, scales, and a lot of measuring equipment.Well as you can see i have "Cadastro" as my root element, "Instrumento" or instrument is the element that holds the info of the equipment.For my problem i have to query on the xml three elements from "instrumento", they are: <idsetor></idsetor>: this one holds the sector which the equipment belongs to. (its a number)<idgrupo></idgrupo>: this oneindicates the group of the equipment like(Digital caliper, Pressure Gauge,...) (its a number) <idsequencia></idsequencia>: this one indicates the sequential number of the equipment by order of arrival and registry (caliper 001, caliper 002, ...,caliper NNN) the <id></id> is a combination formed by the 3 elements above.Well during the registry I input two variables the sector and the group but the sequential number should be generated automaticaly obeying the sequence of the already registered equipments. my logic is request all the instruments with the same <idsetor> and <idgrupo> and after select from this set, the one with the highest <idsequencia>, and then: idsequencia = idsequencia + 1; Now reading about Xpath in the internet I got to this two Xpaths: 1 - "cadastro/instrumento[idsetor=+IDSETORaux+" and idgrupo="+IDGRUPOaux+]/idsequencia"2 - "/cadastro/instrumento/idsequencia[not(/cadastro/instrumento/idsequencia>.)]"

  • The first returns all the <idsequencia> of all the instruments that have the same idsetor and idgrupo, pointed by the variables IDSETORaux and IDGRUPOaux respectively.
  • The second returns te highest <idsequencia> of all the registered elements.

Well I have been playing with this two xpaths, combining them in diferent ways but no success. Now i turn to you and ask, can you help me please???

Link to comment
Share on other sites

Well Guys thanks to your time!! I continued trying and got to this XPath:Xpath = "/cadastro/instrumento[idsetor=+IDSETORaux+" and idgrupo="+IDGRUPOaux+]/idsequencia[not(/cadastro/instrumento[idsetor=+IDSETORaux+" and idgrupo="+IDGRUPOaux+]/idsequencia>.)]"; It's very big but works so far. Does any one could write it in a better way? Is this possible? Or could some one just explain what it means? Thanks.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...