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. }
<p name="section-title">
, we should wrap it and the following<p>
elements in a<body-contents>
element (up to the next section-title<p>
). What other rules are there? Also, you mention that you have solved the problem of h1,h2,h3... so what part have you not solved? More in following comment... – LarsH