Php 更换每个跨度元件

Php 更换每个跨度元件,php,xslt,Php,Xslt,我正在尝试匹配DOM文档中的多个span元素 以下是我当前使用的XSLT: <xsl:stylesheet version="1.0" xmlns:php="http://php.net/xsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="utf-8"/> <xsl:template match="html">

我正在尝试匹配DOM文档中的多个span元素

以下是我当前使用的XSLT:

<xsl:stylesheet version="1.0"  xmlns:php="http://php.net/xsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" encoding="utf-8"/>

  <xsl:template match="html">
      <xsl:apply-templates select="./*"/>
  </xsl:template>

  <xsl:template match="/html/body">
      <body>
          <xsl:apply-templates/>
      </body>
  </xsl:template>

  <xsl:template match="/html/head">
      <head>
          <xsl:copy-of select='.'/>
          <link type="text/css" href="additional-style.css" rel="stylesheet"/>
      </head>
  </xsl:template>

  <xsl:template match="//script|//style|//link|//meta">
      <xsl:copy-of select='.'/>
  </xsl:template>

  <xsl:template match="/html/body/*">
      <xsl:copy-of select='.'/>
  </xsl:template>

  <xsl:template match="//span">
      HELLO I'M A SPAN
  </xsl:template>

</xsl:stylesheet>

你好,我是斯潘
目前,无论我将
放在XSLT文档的何处,跨度都不会改变。如果我删除
节,它确实可以工作。如何保持以前的行为并激活匹配?

您必须使用

  <xsl:template match="/html/body/*">
      <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
      </xsl:copy>
  </xsl:template>

以确保使用匹配的模板处理子节点。然而,这通常是通过简单的

  <xsl:template match="@* | node()">
      <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
      </xsl:copy>
  </xsl:template>


另外请注意,在匹配模式中,不需要使用前导的
/
,例如
..
就可以了。

非常有效,谢谢。请给出一个链接来解释那是什么
@*|node()
?编辑:投票通过,将尽快验证。我发布的带有
match=“@*| node()”
的模板就是所谓的身份转换模板,它匹配属性节点(
@*
)以及除名称空间节点和根节点之外的所有其他类型的节点,并对节点本身进行浅层复制,然后处理任何属性节点和任何子节点。它通常是样式表的起点,希望复制输入的一些节点,然后操作/转换或删除其他节点,因为您可以轻松地添加具有更具体匹配模式的进一步模板。