Xml XSLT-断开列表列表项中有什么特殊节点
这里有一个xmlXml XSLT-断开列表列表项中有什么特殊节点,xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,这里有一个xml <doc> <list list-type="alpha-lower"> <list-item> <label>*</label> <p>text1</p> <list list-type="order"> <list-item>
<doc>
<list list-type="alpha-lower">
<list-item>
<label>*</label>
<p>text1</p>
<list list-type="order">
<list-item>
<label>**</label>
<p>text2</p>
</list-item>
<list-item>
<label>***</label>
<p>text3</p>
<non-normative-note>non-normative-text</non-normative-note>
</list-item>
<list-item>
<label>****</label>
<p>text4</p>
</list-item>
<list-item>
<label>*****</label>
<p>text5</p>
</list-item>
<list-item>
<label>******</label>
<p>text6</p>
</list-item>
</list>
</list-item>
<list-item>
<label>*******</label>
<p>text7</p>
<list list-type="order">
<list-item>
<label>********</label>
<p>text8</p>
</list-item>
<list-item>
<label>*********</label>
<p>text9</p>
</list-item>
<list-item>
<label>**********</label>
<p>text10</p>
</list-item>
</list>
</list-item>
</list>
</doc>
*
文本1
**
文本2
***
文本3
非规范性文本
****
文本4
*****
文本5
******
文本6
*******
文本7
********
文本8
*********
文本9
**********
文本10
我需要将嵌套列表与其父列表断开,如果
中存在
节点,则需要断开该列表
这是我的预期产出
<doc>
<list list-type="alpha-lower">
<list-item>
<label>*</label>
<p>text1</p>
</list-item>
</list>
<list list-type="order">
<list-item>
<label>**</label>
<p>text2</p>
</list-item>
<list-item>
<label>***</label>
<p>text3</p>
</list-item>
</list>
<p><non-normative-note>non-normative-text</non-normative-note> </p>
<list list-type="order">
<list-item>
<label>****</label>
<p>text4</p>
</list-item>
<list-item>
<label>*****</label>
<p>text5</p>
</list-item>
<list-item>
<label>******</label>
<p>text6</p>
</list-item>
</list>
<list list-type="alpha-lower">
<list-item>
<label>*******</label>
<p>text7</p>
</list-item>
</list>
<list list-type="order">
<list-item>
<label>********</label>
<p>text8</p>
</list-item>
<list-item>
<label>*********</label>
<p>text9</p>
</list-item>
<list-item>
<label>*********</label>
<p>text10</p>
</list-item>
</list>
</doc>
*
文本1
**
文本2
***
文本3
非规范性文本
****
文本4
*****
文本5
******
文本6
*******
文本7
********
文本8
*********
文本9
*********
文本10
这是我现在拥有的XSLT
<xsl:template match="list[descendant::list]">
<xsl:variable name="type" select="@list-type"/>
<xsl:for-each select="list-item">
<list list-type="{$type}">
<list-item>
<xsl:apply-templates select="node()[not(self::list)]"/>
</list-item>
</list>
<xsl:apply-templates select="list"/>
</xsl:for-each>
</xsl:template>
这将成功地断开嵌套列表,当出现
时,我需要将其扩展为断开列表。你知道我该怎么做吗?你可以在这里使用xsl:for each group
,其中group以
结尾,这样你就可以打破
尝试将这两个模板添加到XSLT中
<xsl:template match="list">
<xsl:variable name="type" select="@list-type"/>
<xsl:for-each-group select="list-item" group-ending-with="*[non-normative-note]">
<list list-type="{$type}">
<xsl:apply-templates select="current-group()" />
</list>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="list-item[non-normative-note]">
<xsl:copy>
<xsl:apply-templates select="@*|node() except non-normative-note" />
</xsl:copy>
<p><xsl:copy-of select="non-normative-note" /></p>
</xsl:template>