'concate sub-elements by parent to get final string xml using xpath and java

I want to concat unsing the sep "-" the sub-elements in the parents node but i got redondance of the first elements founds :

taking this xml element for example :

<BIN>
  <REVST>
  </REVST>
  <TITLE>INFORMATION</TITLE>
  <REV>For
    <MATRG>
      <MATST>
        <MATSET>01
        </MATSET>
      </MATST>
      <MATIND>
        <MATSET>13
        </MATSET>
      </MATIND>
    </MATRG>:
  </REV>
  <REV>For 
    <MATRG>
      <MATST>
        <MATSET>01
        </MATSET>
      </MATST>
      <MATIND>
        <MATSET>06
        </MATSET>
      </MATIND>
    </MATRG>:
  </REV>
  <REV>For 
    <MATSET>223
    </MATSET>
  </REV>
  <END>
  </END>
</BIN>

My try :

private static final XPathExpression MATSTPATH;
private static final XPathExpression MATNDPATH;
MATSTPATH= XPATH.compile("/BIN/*[preceding-sibling::TITLE[text()='INFORMATION']]/MATRG/MATST");
MATNDPATH= XPATH.compile("/BIN/*[preceding-sibling::TITLE[text()='INFORMATION']]/MATRG/MATIND");

public static String getMATSET(Node node, Element e) {
        String res= "";
        String matset = getString(MATSTPATH, node);
        processed = matset + "-" ;
        String matse2= getString(MATNDPATH, node);
        processed = processed + matset2;
        return res;
    }

while looping on the nodes : I got redondancy like :

1. 01-13
2. 01-13

instead of :

1. 01-13
2. 01-06


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source