如果这已经在另一篇帖子中被问到并得到了回答,我提前道歉。
我一直在思考这个问题,但还没有找到一个完整的解决方案。
我的问题是:
我有几个案例,其中父元素包含多组直接的兄弟元素。每个集合都需要与它们的任何子元素合并到一个元素中。每组都穿插着文字。例如:
XML输入
<p>Information about specific mio levels, accessed as
<codeph><i>metaMio</i></codeph><codeph>[</codeph><codeph><i>N</i></codeph><codeph>]</codeph>
, in which
<codeph><i>N</i></codeph><codeph> < kMaxMioLevels</codeph>
.
</p>
所需的XML输出
<p>Information about specific mio levels, accessed as
<codeph><i>metaMio</i>[<i>N</i>]</codeph>
, in which
<codeph><i>N</i> < kMaxMioLevels</codeph>
.
</p>
这是我到目前为止所尝试的,但我发现它重复了第二组中第二个元素的内容:
尝试XSLT
<xsl:template match="codeph[not(preceding-sibling::node()[1][./local-name()='codeph'])][following-sibling::node()[1][./local-name()='codeph']]">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates/>
<xsl:choose>
<xsl:when test="following-sibling::codeph[preceding-sibling::node()[position()=1][local-name()='codeph']]">
<xsl:apply-templates select="following-sibling::codeph[preceding-sibling::node()[position()=1][local-name()='codeph']]" mode="codeph-merger"/>
</xsl:when>
<xsl:when test="following-sibling::*[1][text()[not(parent::codeph)]]"/>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="*" mode="codeph-merger">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="codeph[preceding-sibling::node()[1][local-name()='codeph']]"/>
电流输出
上面的XSLT创建了以下输出,该输出很接近,但重复了文本(
< kMaxMipLevels
):
<p>Information about specific mio levels, accessed as
<codeph><i>metaMio</i>[<i>N</i>] < kMaxMipLevels</codeph>
, in which
<codeph><i>N</i> < kMaxMipLevels</codeph>
.
</p>
我还尝试将组邻近用作xsl:for-each组的一部分,但找不到任何方法来处理这种情况。
我使用XSLT 2.0和Saxon HE 12.4作为DITA-OT 4.2.4的一部分。
感谢您提供的任何帮助。