Xml 使用xslt将h3带到p之外

Xml 使用xslt将h3带到p之外,xml,xslt-1.0,Xml,Xslt 1.0,输入是- <data> <container> <strong>Code Development</strong> <br/> here to support <ul class="nested"> <li>list 1</li> <li>list 2</li&

输入是-

    <data>
      <container>
        <strong>Code Development</strong>
        <br/>
        here to support
        <ul class="nested">
          <li>list 1</li>
          <li>list 2</li>
          <li>list 3</li>
          <li>list 4</li>
        </ul>
something here
<strong>this is strong</strong>
      </container>
    </data>

代码开发

来支持
  • 清单1
  • 清单2
  • 清单3
  • 清单4
这里有东西 这是strong
预期产出-

            <h3>Code Development</h3>
        <p>
        here to support
        <ul class="nested">
          <li>list 1</li>
          <li>list 2</li>
          <li>list 3</li>
          <li>list 4</li>
        </ul>
      </p>

<h3>this is strong</h3>
<p>    something here</p>
代码开发

来支持
  • 清单1
  • 清单2
  • 清单3
  • 清单4

这是强大的 这里有东西

强标记应该变成h3,因为h3不能在
内,所以将它移到p外,作为第一个出现在p之前的标记

试试这个:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="strong">
        <h3><xsl:value-of select="."/></h3>
    </xsl:template>

    <xsl:template match="container/text()">
        <xsl:if test="string-length(normalize-space()) > 0">
            <p><xsl:value-of select="."/></p>
        </xsl:if>
    </xsl:template>

    <xsl:template match="ul">
        <xsl:copy-of select="."/>
    </xsl:template>

</xsl:stylesheet>


下面是一个实际的例子:

你到底在哪里处理这个问题?Michael-我想处理p标签外的h3和p标签内的所有其他内容。不确定,如何避免只是我担心你错过了我的重点。如果你有一个特别的困难,指出它-最好是张贴你已经尝试过的。否则看起来你是想找人帮你工作。谢谢你的邀请。实际上,我需要把所有的东西都放在p标签里面,除了强标签。所以,ul应该包含在p中。只是我需要避免h3在p里面,当p标签要构建的时候,把它放在外面。