Here is my requirement. My sample input document is like below. (I have added white lines to make it clear)
<body>
<p name="h-title" other="main">Introduction</p>
<p name="h-titledesc " other="other-desc">XSLT and XQuery</p>
<p name=""> XSLT is used to write stylesheets.</p>
<p name="section-title" other=" other-section">XSLT</p>
<p name="section-desc" other=" other-sectionsdesc">XSLT</p>
<p name=""> Some text.</p>
<p name="">
<p1 name="bold"> XQuery is used to query XML databases.</p1>
</p>
<p name="h1-title" other=" other-h1">XSLT</p>
<p name=""> Some text.</p>
<p name="h2-title " name="other-h2">XQuery</p>
<p name="">
<p1 name="bold"> XQuery is used to query XML databases.</p1>
</p>
<p name="h3-title" name="other-h3">XQuery and stylesheets</p>
<p name="">
<p1 name="bold"> XQuery is used to query XML databases.</p1>
</p>
<p name="section-title" other=" other-section">XSLT</p>
<p name="section-desc" other=" other-sectionsdesc">XSLT</p>
<p name=""> Some text.</p>
<p name="">
<p1 name="bold"> XQuery is used to query XML databases.</p1>
</p>
<p name="h1-title" other=" other-h1">XSLT</p>
<p name=""> Some text.</p>
<p name="h2-title " name="other-h2">XQuery</p>
<p name="">
<p1 name="bold"> XQuery is used to query XML databases.</p1>
</p>
<p name="h3-title" name="other-h3">XQuery and stylesheets</p>
<p name="">
<p1 name="bold"> XQuery is used to query XML databases.</p1>
</p>
<p name ="summary-title">this is summary</p>
<p name="summary-desc " other="other-summarydesc">the summary</p>
</body>
Now my wanted output is this.
<body>
<p name="h-title" other="main">Introduction</p>
<p name="h-titledesc " other="other-desc">XSLT and XQuery</p>
<p name=""> XSLT is used to write stylesheets.</p>
<body-contents>
<p name="section-title" other=" other-section">XSLT</p>
<p name="section-desc" other=" other-sectionsdesc">XSLT</p>
<p name=""> Some text.</p>
<p name="">
<p1 name="bold"> XQuery is used to query XML databases.</p1>
</p>
<h1>
<p name="h1-title" other=" other-h1">XSLT</p>
<p name=""> Some text.</p>
<h2>
<p name="h2-title " name="other-h2">XQuery</p>
<p name="">
<p1 name="bold"> XQuery is used to query XML databases.</p1>
</p>
<h3>
<p name="h3-title" name="other-h3">XQuery and stylesheets</p>
<p name="">
<p1 name="bold"> XQuery is used to query XML databases.</p1>
</p>
</h3>
</h2>
</h1>
</body-contents>
<body-contents>
<p name="section-title" other=" other-section">XSLT</p>
<p name="section-desc" other=" other-sectionsdesc">XSLT</p>
<p name=""> Some text.</p>
<p name="">
<p1 name="bold"> XQuery is used to query XML databases.</p1>
</p>
<h1>
<p name="h1-title" other=" other-h1">XSLT</p>
<p name=""> Some text.</p>
<h2>
<p name="h2-title " name="other-h2">XQuery</p>
<p name="">
<p1 name="bold"> XQuery is used to query XML databases.</p1>
</p>
<h3>
<p name="h3-title" name="other-h3">XQuery and stylesheets</p>
<p name="">
<p1 name="bold"> XQuery is used to query XML databases.</p1>
</p>
</h3>
</h2>
</h1>
</body-contents>
<body-contents>
<p name ="summary-title">this is summary</p>
<p name="summary-desc " other="other-summarydesc">the summary</p>
</body-contents>
</body>
Please help me solve this problem.
{OPTIONAL
There are restrictions like:
- h1, h2, h3 come sequentially(that means, h3 does not come between h1 and h2)
- lines with name=”section-title” should come before name=”section-desc”
- h1, h2, h3, etc. should come after section-desc.
I solved the problem of h1,h2,h3,etc here. I know this is very had. Any help is great.
The transformation should not happen if these rules violate.
}
Here is my adaption of the previously posted stylesheet, it simply does an additional
group-starting-withbefore calling the recursive function grouping the levels. I realize that is kind of the same suggestion as in an earlier post you made but so far it is not clear to me why that suggestion does not work for you.So here is the stylesheet:
When I apply that stylesheet with Saxon 9.4 to the corrected input
I get the output
Please next time when you provide an input sample make sure it is well-formed, so far you have always posted stuff like
<p name="h2-title " name="other-h2">XQuery</p>, and two attributes of the same name are not possible.