将'p&39;元素内容合并到以下&p元素内容下 [英] Merge 'p' element content under the following 'p element' content

查看:14
本文介绍了将'p&39;元素内容合并到以下&p元素内容下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是列表内容,现在项目符号列表和项目内容分别出现在输出中。 所以我想合并一个<p>,请查看预期的输出并帮助我。 提前感谢

输入XML:

<kk>
    <group class="li">
        <line>
            <t style="li">•</t>
        </line>
    </group>
    <group class="p">
        <line>
            <t style="p">content here</t>
        </line>
        <line>
            <t style="p">content here1</t>
        </line>
        <line>
            <t style="p">content here2</t>
        </line>
    </group>    
</kk>

当前产量:

<kk>
    <group class="li">
        <line>
            <t style="li">• content here content here1 content here2</t>
        </line>
    </group>
</kk>

当前XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="p">
        <p>
            <xsl:apply-templates/>
        </p>
    </xsl:template>
    
</xsl:stylesheet>

预期产量:

<kk>
<p>• content here</p>
</kk>

For-Each-推荐答案GROUP-STARTING-WITH合并以项目符号开头的任何元素的

  <xsl:template match="kk">
    <xsl:copy>
      <xsl:for-each-group select="group" group-starting-with="group[@class = 'li' and ki/p[@class = 'li'] = '•']">
        <p>
          <xsl:value-of select="current-group()//p"/>
        </p>
      </xsl:for-each-group>
    </xsl:copy>
  </xsl:template>

这篇关于将&#39;p&39;元素内容合并到以下&p元素内容下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆