in reply to how to change node value based on other node value

but that doesnt work. I cant figure out how to change the voltage based on the value of Name.

"doesn't work" isn't diagnostic ... :)

but, even in xpath, you can't make syntax up :) grab xpather.pl and see what it spits out

/Settings/Channels/Channel[4] # posy /Settings[1]/Channels[1]/Channel[4] # star /*[ local-name() = "Settings" and position() = 1 ] /*[ local-name() = "Channels" and position() = 1 ] /*[ local-name() = "Channel" and @Name = "L360" and @Voltage = "120" and @Test = "1" ] # rats /Settings[1] /Channels[1] /*[ name() = "Channel" and position() = 4 and @Name = "L360" and @Vol +tage = "120" and @Test = "1" ]

So next step is adjust your xpath to be valid :)

Replies are listed 'Best First'.
Re^2: how to change node value based on other node value
by ccherri (Acolyte) on Apr 08, 2015 at 17:30 UTC

    wow Anonymous Monk, that is cool. But whaddaya mean I can't just make up my own syntax??? Seriously tho, I want to know how this works so I can learn and stop asking newbie questions (been at perl a few years now, xml about a week). So I see #posy and that looks like an xpath and returns (using findnode) an indexed channel (but I don't see how that guarantees it is the channel i want based on name, not index value) and star and rats throw me. I tried all reasonable variations as xpaths and get nothing but errors (invalid expression) or empty results. I see using the //tagname option limits the output to the bits I am interested in but still am not sure what to make of it. Any help or pointers to help is much appreciated. ~Chris

      um, as a path you wrote  '/Settings/Channels/Channel/Name="L1"'

      xpather shows what you should have written

      /Settings[1] /Channels[1] /*[ name() = "Channel" and @Name = "L1"]

      or findnodes( q{ //Channel[ @Name = "L1" and @Voltage = "400" ] } )