任何元素/文本都应与使用 xslt 的 <p> 标签分开<p>

问题描述 投票:0回答:1
xml xslt
1个回答
0
投票
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
  exclude-result-prefixes="xs xd"
  version="2.0">
  
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="p[table]">
    <!-- If p contains table  put everything before and after table in p and the table it self not in p-->
    <xsl:for-each-group select="node()" group-adjacent="if(self::table) then 1 else 0">
      <xsl:choose>
        <xsl:when test="current-group()[self::table]">
          <xsl:apply-templates select="current-group()"/>
        </xsl:when>
        <xsl:otherwise>
          <p>
            <xsl:apply-templates select="current-group()"/>
          </p>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each-group>
  </xsl:template>
  
</xsl:stylesheet>
© www.soinside.com 2019 - 2024. All rights reserved.