views:

27

answers:

1

I have the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<test-report>
<testsuite>
<test name="RegisterConnection1Tests">
<testcase name="testRregisterConnection001"></testcase>
<testcase name="testRegisterConnection002"></testcase>
</test>
<test name="RegisterConnection2Tests">
<testcase name="testRregisterConnection001"></testcase>
<testcase name="testRegisterConnection002"></testcase>
</test>
</testsuite>
</test-report>

And I want the output:

RegisterConnection1Tests,testRregisterConnection001
RegisterConnection1Tests,testRregisterConnection002
RegisterConnection2Tests,testRregisterConnection001
RegisterConnection2Tests,testRregisterConnection002

I'm confused as to how to show the children as I expected

xmlstarlet sel -t -m 'test-report/testsuite/test' -v '@name' -v '//testcase/@name' -n $1 to work, though it only inputs:

RegisterConnection1TeststestRregisterConnection001
RegisterConnection2TeststestRregisterConnection001
A: 

To add the missing comma you can add another -v "','" In your second column you are selecting with an absolute xpath expression from the root element and not from the element matched by the template, the double slashes are wrong. Since you want one line per testcase I would iterate over the testcase elements and then add the name attribute of the parent element like this:

xmlstarlet sel -t -m 'test-report/testsuite/test/testcase' -v '../@name' -v "','" -v '@name' -n $1
Jörn Horstmann
No, still wrong. $ xmlstarlet sel -t -m 'test- report/testsuite/test' -v '@name' -v "','" -v 'testcase/@name' -n test.xml RegisterConnection1Tests,testRregisterConnection001RegisterConnection2Tests,testRregisterConnection001
hendry
ah, didn't realise you could do a ../ parent thing like that. Clever!
hendry