【发布时间】:2012-07-27 18:16:45
【问题描述】:
这是我的要求。我的示例输入文档如下所示。 (我添加了白线以使其清晰)
<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>
现在我想要的输出是这个。
<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>
请帮我解决这个问题。
{可选 有如下限制:
- h1、h2、h3 依次出现(也就是说,h3 不在 h1 和 h2 之间)
- name="section-title" 的行应该在 name="section-desc" 之前
- h1、h2、h3 等应在 section-desc 之后。
我解决了h1、h2、h3等here的问题。我知道这很了不起。任何帮助都很棒。
如果违反这些规则,则不应发生转换。 }
【问题讨论】:
-
我认为如果您以更完整和更有条理的方式布置规则和“限制”会更容易。如果输入违反限制会发生什么?更重要的是,尽量使转换规则明确,而不是要求我们推断它们,这会导致不同的解释。
-
谢谢@LarsH 告诉我。我组织了它。我在问题中提出了 3 个限制。
-
感谢您对限制进行更清晰的组织。我修复了项目符号格式。我想说的是,你能说出转换规则吗?例如。似乎有一条规则,每次我们有一个
<p name="section-title">,我们都应该将它和下面的<p>元素包装在一个<body-contents>元素中(直到下一节标题<p>)。还有哪些其他规则?另外,你提到你已经解决了h1,h2,h3的问题......那么你没有解决什么部分?更多在下面的评论... -
Setinger,这个长线程反映了这个问题很难理解的事实。怀着深深的敬意,我建议您特别注意编写简单、定义明确且易于理解的问题,否则人们可能会完全停止阅读它们。
-
我很抱歉 Dimitre。在接下来的问题中我会更清楚。幸运的是,马丁给出了答案。