将 / 添加到<ol><ul>所有<li>没有 / 的标记,因为它<ol><ul>是父 XSLT



我有这种xml,其中some <li> tags没有<ol>/<ul>作为它的父级。需要添加为其父项。

示例:

<root>
<p>some text</p>
<ol>
<li>
<a href="http://cowherd.com" rel="nofollow">http://cowherd.com</a>
</li>
</ol>
<li>some text</li>
<li>some text</li>
<p>some more text</p>
<li>some text in li.</li>
<p>some more text</p>
<li>some text in li.</li>
</root>   

所需输出:我想给那些没有父as <ol>/<ul><li>tags添加一个父<ol>or<ul>标记。此外,如果连续有一个以上的<li> tag then all the <li> tags should come under same <ul>/<ol>just like below.,请提前感谢。

<root>
<p>some text</p>
<ol>
<li>
<a href="http://cowherd.com" rel="nofollow">http://cowherd.com</a>
</li>
</ol>
<ol>
<li>some text</li>
<li>some text</li>
</ol>
<p>some more text</p>
<ol> 
<li>some text in li.</li>
</ol>
<p>some more text</p>
<ol>
<li>some text in li.</li>
</ol>
</root>

开始:

如果那些没有父olli可以在任何地方出现,请使用以下匹配:

<xsl:template match="*[li[not(parent::lo)]]">

就像@Martin Honnen在他的评论中建议使用

<xsl:for-each-group select="*" group-adjacent=". instance of element(li)">

在该组循环中,您可以使用current-grouping-key()current-group()

最新更新