在 XSLT 2 中对多个组进行分组
我正在尝试将层次结构添加到一些糟糕的挤压排版 XML 中。我似乎无法同时将多种组分组到同一父元素中。
我所拥有的(显然是简单的):
<article>
<h1>A section title here</h1>
<p>A paragraph.</p>
<p>Another paragraph.</p>
<bl>Bulleted list item.</bl>
<bl>Another bulleted list item.</bl>
<h1>Another section title</h1>
<p>Yet another paragraph.</p>
</article>
我想要的:
<article>
<sec>
<h1>A section title here</h1>
<p>A paragraph.</p>
<p>Another paragraph.</p>
<list>
<list-item>Bulleted list item.</list-item>
<list-item>Another bulleted list item.</list-item>
</list>
</sec>
<sec>
<h1>Another section title</h1>
<p>Yet another paragraph.</p>
</sec>
</article>
这几乎适用于列表项:
<xsl:for-each-group select="*" group-adjacent="boolean(self::BL)">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<list><xsl:apply-templates select="current-group()"/></list>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
但它只处理文章中的第一个列表;一旦我尝试添加另一个 xsl:for-each-group 来覆盖这些部分,列表项就会停止工作。
有想法吗?非常感谢!
I'm trying to add hierarchy to some grotty extruded typesetting XML. I can't seem to manage grouping several kinds of groups in the same parent element at once.
What I have (simplified, obviously):
<article>
<h1>A section title here</h1>
<p>A paragraph.</p>
<p>Another paragraph.</p>
<bl>Bulleted list item.</bl>
<bl>Another bulleted list item.</bl>
<h1>Another section title</h1>
<p>Yet another paragraph.</p>
</article>
What I want:
<article>
<sec>
<h1>A section title here</h1>
<p>A paragraph.</p>
<p>Another paragraph.</p>
<list>
<list-item>Bulleted list item.</list-item>
<list-item>Another bulleted list item.</list-item>
</list>
</sec>
<sec>
<h1>Another section title</h1>
<p>Yet another paragraph.</p>
</sec>
</article>
This almost works for the list items:
<xsl:for-each-group select="*" group-adjacent="boolean(self::BL)">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<list><xsl:apply-templates select="current-group()"/></list>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
but it only handles the very first list in an article; and as soon as I try to add another xsl:for-each-group to cover the sections, the list-item one stops working.
Ideas? Many thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是一个示例样式表,它生成您为您发布的输入示例发布的输出:
Here is a sample stylesheet that produces the output you posted for the input sample you posted: