我有这个 xml:
<text>
blah blah <strong> hello </strong> more text <strong>hello again</strong> blah blah
</text>
如何选择强标签中已转义的文本<
和>
在此示例中,选择应为:
- 你好
- 再一次问好
更新需要 XSLT 1.0
Since you have updated saying you can only use XSLT 1 - See this post: How to use XSLT 1.0 or XPath to manipulate an HTML string
This is a little complex but:
To replace <, >, and & you'll have to clean it three times...
Here is some XSLT to get you started:
<xsl:variable name="cleanXML">
<xsl:call-template name="SubstringReplace">
<xsl:with-param name="stringIn">
<xsl:call-template name="SubstringReplace">
<xsl:with-param name="stringIn">
<xsl:call-template name="SubstringReplace">
<xsl:with-param name="stringIn">
<xsl:call-template name="SubstringReplace">
<xsl:with-param name="stringIn" select="$theXml"/>
<xsl:with-param name="substringIn" select="'&lt;'"/>
<xsl:with-param name="substringOut" select="'<'"/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="substringIn" select="'&gt;'"/>
<xsl:with-param name="substringOut" select="'>'"/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="substringIn" select="'&amp;'"/>
<xsl:with-param name="substringOut" select="'&'"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
这是一个 C# 实现。
使用的命名空间
using System.Xml
using System.Web
执行
//Read xml file
string xmlText = "<text>blah blah <strong> hello </strong> more text <strong>hello again</strong> blah blah</text>";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(HttpUtility.HtmlDecode(xmlText));
XmlNodeList Nodes = doc.GetElementsByTagName("strong");
List<string> nodeValues= new List<string>();
foreach (XmlNode Node in Nodes)
{
nodeValues.Add(Node.InnerText);
}