替换<;在XML/HTML格式中,带;(正则表达式)

替换<;在XML/HTML格式中,带;(正则表达式),html,xml,regex,replace,epub,Html,Xml,Regex,Replace,Epub,我有一个XML/HTML(epub)文档,它的内容是,而不是”,用于引用。是否有可能只替换内容,而保留不被某些正则表达式触及? 您的问题并不完全清楚,但听起来您的XML中有一些文本值,其中包含,您希望将其更改为引号。使用XSLT可以相当容易地做到这一点: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent

我有一个XML/HTML(epub)文档,它的内容是
,而不是
,用于引用。是否有可能只替换内容
,而保留
不被某些正则表达式触及?

您的问题并不完全清楚,但听起来您的XML中有一些文本值,其中包含
,您希望将其更改为引号。使用XSLT可以相当容易地做到这一点:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

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

  <xsl:template match="text()">
    <xsl:value-of select="translate(., '&lt;&gt;', '&quot;&quot;')"/>
  </xsl:template>
</xsl:stylesheet>

在该输入上运行时:

<root>
  <item>And he said &lt;hello!&gt;.</item>
  <item>&lt;hello!&gt;, he said</item>
  <section>
    <content>&lt;What's up&gt;</content>
  </section>
</root>

他说你好!。
你好他说
怎么了
它产生:

<root>
  <item>And he said "hello!".</item>
  <item>"hello!", he said</item>
  <section>
    <content>"What's up"</content>
  </section>
</root>

他说:“你好!”。
“你好!”他说
“怎么了?”

文档中的文本是否有可能包含您不想转换为引号的
内容?

您能举个例子吗?只是为了确定,它们看起来像
?这个问题不清楚。请举例说明。