Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 我需要使用单个模板删除所有系列标记_Xml_Xslt_Xslt 2.0 - Fatal编程技术网

Xml 我需要使用单个模板删除所有系列标记

Xml 我需要使用单个模板删除所有系列标记,xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,是否可以使用XSL删除h系列号 使用以下格式输入XML: <table> <tbody> <tr> <td> <h2> <img src="https://admin.com" /> </h2> </td> <td> <h3>

是否可以使用XSL删除h系列号

使用以下格式输入XML:

  <table>
    <tbody>
      <tr>
        <td>
          <h2>
            <img src="https://admin.com" />
          </h2>
        </td>
        <td>
          <h3>
            <img src="https://admin.com" />
          </h3>
        </td>
        <td>
          <h4>
            <img src="https://admin.com" />
          </h4>
        </td>
      </tr>
    </tbody>
  </table>
XSL I用作:

<xsl:template match="table/tbody/tr/td/h2[img]">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="table/tbody/tr/td/h3[img]">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="table/tbody/tr/td/h4[img]">
  <xsl:apply-templates/>
</xsl:template>
与所有输入一样,表中可能有h批次。是否可以编写单个模板来删除所有h1 h2 h3。。。。。。。表中的h系列?

您可以在示例模板中使用多个s,例如

我不建议使用正则表达式,如果您想缩短模式,那么也许可以这样做

<xsl:template match="table/tbody/tr/td/*[(self::h1 | self::h2 | self::h3 | self::h4 | self::h5 | self::h6) and img]">
  <xsl:apply-templates/>
</xsl:template>

嗨,马丁。谢谢这是否可以对要删除的h系列编号使用任何正则表达式。请建议??我不确定在模式中使用正则表达式来匹配不同的元素名称是否是一个好主意,您当然可以尝试例如。*[matchesname,^h1 | 2 | 3 | 4 | 5 | 6$”,但为了清晰和高效,最好在模式的一个步骤中拼写出元素名称。