I have an XML file with consecutive tags instead of nested tags, like the following:
<title>
<subtitle>
<topic att="TopicTitle">Topic title 1</topic>
<content att="TopicSubtitle">topic subtitle 1</content>
<content att="Paragraph">paragraph text 1</content>
<content att="Paragraph">paragraph text 2</content>
<content att="TopicSubtitle">topic subtitle 2</content>
<content att="Paragraph">paragraph text 1</content>
<content att="Paragraph">paragraph text 2</content>
<topic att="TopicTitle">Topic title 2</topic>
<content att="TopicSubtitle">topic subtitle 1</content>
<content att="Paragraph">paragraph text 1</content>
<content att="Paragraph">paragraph text 2</content>
<content att="TopicSubtitle">topic subtitle 2</content>
<content att="Paragraph">paragraph text 1</content>
<content att="Paragraph">paragraph text 2</content>
</subtitle>
</title>
I'm using XQuery in BaseX and I want to convert it to a table with the following columns:
Title Subtitle TopicTitle TopicSubtitle Paragraph
Irrelevant Irrelevant Topic title 1 Topic Subtitle 1 paragraph text 1
Irrelevant Irrelevant Topic title 1 Topic Subtitle 1 paragraph text 2
Irrelevant Irrelevant Topic title 1 Topic Subtitle 2 paragraph text 1
Irrelevant Irrelevant Topic title 1 Topic Subtitle 2 paragraph text 2
Irrelevant Irrelevant Topic title 2 Topic Subtitle 1 paragraph text 1
Irrelevant Irrelevant Topic title 2 Topic Subtitle 1 paragraph text 2
Irrelevant Irrelevant Topic title 2 Topic Subtitle 2 paragraph text 1
Irrelevant Irrelevant Topic title 2 Topic Subtitle 2 paragraph text 2
I'm new to XQuery and XPath but I already understand the basics on how to navigate through nodes and select the ones I need. What I don't know yet is how to work with consecutive data that I want to convert to a nested XML or table (CSV?). Can anyone help?