in reply to Extraction of value with XMLLIB

The basic problem is your XPath expression doesn't follow the structure of the document. <mt> is not a child of <md>, there's a <mi> in between. Therefore, something like the following should match all the VAL nodes:
/mdc/md/mi/mt[contains(.,"VAL")]

The same holds for the <r> elements: their parent is <mv>.

The following works for me:

#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use XML::LibXML; my @val; my $doc = 'XML::LibXML'->load_xml( location => 'file.xml' ); for my $book ($doc->findnodes('/mdc/md/mi/mt[contains(.,"VAL")]')) { my $order = 1 + $book->findvalue('count(preceding-sibling::mt)'); my $rs = $book->findnodes("../mv/r[$order]"); say join ', ', map $_->textContent, $book, @$rs; }

You can get the same logic with XML::XSH2, which is a wrapper around XML::LibXML:

open file.xml ; for /mdc/md/mi/mt[xsh:match(.,'^VAL[0-9]+')] { my $order = 1 + count(preceding-sibling::mt) ; echo xsh:join(', ', (.), ../mv/r[$order]) ; }

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Extraction of value with XMLLIB
by shak (Initiate) on May 06, 2015 at 12:04 UTC
    Hi All, Thanks for the information "count(preceding-sibling)" helped , can have the feature available in LibXML Also is it possible to add the NAME also. Once Again thanks
      I don't understand. Are you requesting the count feature to exist in LibXML? My first example shows it exists already.

      There was no NAME in your original question, only SNAME. There's only one SNAME per CLT, so it's not clear what output you want.

      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        I was not aware of "count(preceding-sibling)" function ,your code just worked fine. I tried google what are the different option available in LibXML but could not find can u help me on that. If wanted the output some thing like VAL1,NAME,0 VAL1,NAME1,0 VAL2,NAME,0 VAL2,NAME1,0