I am using XPath in unix to get the value of attribute as follows:
xpath PM.xml '/*[contains(local-name(),'PM')]/*[contains(local-name(),'family')]/@eventNumber'
which is returning me:
Found 4 nodes:
-- NODE --
eventNumber="000000"-- NODE --
eventNumber="010000"-- NODE --
eventNumber="020000"-- NODE --
eventNumber="030000"
But here I need the value as:
000000
010000
020000
030000
After looking into some examples, I tried functions like string()
, text()
as follows, but didn't work.
SS-03:~/pankaj # xpath PM.xml '/*[contains(local-name(),'PM')]/*[contains(local-name(),'family')]/@eventNumber/text()'
No nodes found
SS-03:~/pankaj # xpath PM.xml '/*[contains(local-name(),'PM')]/*[contains(local-name(),'family')]/@eventNumber/string()'
Parse of expression /*[contains(local-name(),PM)]/*[contains(local-name(),family)]/@eventNumber/string() failed - junk after end of expression: ( at /usr/lib/perl5/vendor_perl/5.10.0/XML/XPath/Parser.pm line 127.
Please correct me where I am wrong. Also, please help me to get this using xpath only, as I have to use this in XSL.
Your xpath is fine, that's only the way the application you used display xpath result. For example, the same xpath when used in XSL like so :
given the following input XML :
yield the expected values in output :