我需要重新排列层次结构(移动出现在段落后面、段落内部的列表):
From: <para updated="20240205"><text> ... </text> ... </para><list type="num"> ... </list>
To: <para updated="20240205"><text> ... </text> ... <list type="num"> ... </list></para>
备注:
我对 XSL 比较陌生,不确定如何处理这个问题,因为它们目前是兄弟姐妹
我还没有尝试任何事情,因为我不知道如何解决这个问题。
谢谢
使用例如
<xsl:template match="*[para]">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:for-each-group select="*" group-starting-with="para">
<xsl:choose>
<xsl:when test="self::para">
<xsl:copy>
<xsl:apply-templates select="@*, node(), tail(current-group())"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
我认为
tail
是 XPath 3/XSLT 3,因此如果您确实使用 XSLT 2 处理器,请改用 subsequence(current-group(), 2)
。
当然,推动一切通过
apply-templates
假设您已经为不想更改的节点设置了身份转换(模板),并为您想要更改的节点上的任何转换添加了模板。