xmllint is a bit finicky to say the least, replacing it with xml starlet should make at least that part easier to follow