Xml 无法使用转义字符
在这一天的匆忙和沮丧中,我显然没有发布足够的相关信息,所以让我重新表述一下这个问题。谢谢你的耐心 我有一些XML返回以下标记:Xml 无法使用转义字符,xml,xslt,Xml,Xslt,在这一天的匆忙和沮丧中,我显然没有发布足够的相关信息,所以让我重新表述一下这个问题。谢谢你的耐心 我有一些XML返回以下标记: etc... <tr> <td class="Label Center">22</td> <td Indentation="4" class="Label Stub Left">Listings</td> <tr> <td class="L
etc...
<tr>
<td class="Label Center">22</td>
<td Indentation="4" class="Label Stub Left">Listings</td>
<tr>
<td class="Label Center">23</td>
<td Indentation="6" class="Label Stub Left">Notes<sup>1</sup></td>
</tr>
etc...
等等。。。
22
列表
23
附注SSUP1/sup
等
我用以下方法处理它们,一切都很好,除了一件事:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8"/>
<xsl:param name="TABLENUM"/>
<xsl:template match="/">
<xsl:for-each select="/Response/MakeStory/div/div[@class='Table'][$TABLENUM]">
<h3 style="margin:2px; padding:0;"><xsl:value-of select="div [@class='TableTitle']"/></h3>
<h4 style="margin:2px; padding:0;"><em><xsl:value-of select="div[@class='TableSubTitle']"/></em></h4>
<xsl:for-each select="div[@class='HtmlTable']/table">
<table cellpadding="3" cellspacing="0">
<xsl:copy-of select="thead"/>
<xsl:apply-templates select="tbody"/>
</table>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template match="tbody">
<xsl:copy>
<xsl:apply-templates select="tr"/>
</xsl:copy>
</xsl:template>
<xsl:template match="tr">
<xsl:copy>
<xsl:apply-templates select="td"/>
</xsl:copy>
</xsl:template>
<xsl:template match="td[contains(@class, 'Left')]">
<td align="left" style="padding-left: {@Indentation * 3}px;">
<xsl:copy-of select="node()"/>
</td>
</xsl:template>
<xsl:template match="td[contains(@class, 'Center')]">
<td align="center">
<xsl:copy-of select="node()" />
</td>
</xsl:template>
我在上面的例子中遇到的问题是,当项目被输出时,转义标记被视为文本,并逐字写出注释1,而不是像下面的注释1那样在数字上加上标
我尝试了很多方法,包括将xsl文本转义字符设置为no wrapped环绕节点,尝试应用模板,而不是使用选择节点的副本选项和选择条件来查找转义字符,但不幸的是,我没有任何运气
处理这个问题的最佳方法是什么。我确信这非常简单,但我对XSLT的有限知识并不能真正做到这一点。如有任何信息,将不胜感激
哦,我“认为”我有XSLT2,但我不确定
谢谢。
< p>为了最小化问题的例子,让我们考虑下面的XML源:<tr>
<td>Notes<sup>1</sup></td>
</tr>
附注SSUP1/sup
以下样式表:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="tr">
<tr>
<xsl:apply-templates select="td"/>
</tr>
</xsl:template>
<xsl:template match="td">
<td>
<xsl:value-of select="." disable-output-escaping="yes"/>
</td>
</xsl:template>
</xsl:stylesheet>
将返回:
<?xml version="1.0" encoding="UTF-8"?>
<tr>
<td>Notes<sup>1</sup></td>
</tr>
附注1
以HTML格式显示的内容将呈现为:
恐怕不太清楚。试着给出一个你的输入和预期输出的例子:这可能会让事情变得更清楚一点。同上:你没有告诉我们你想要发生什么(预期输出),也没有告诉我们实际发生了什么(实际输出)。这个问题已经用更相关的信息进行了修改。感谢您的时间。“我”认为“我有XSLT 2,但我不确定。”这应该很容易找到-请参见下面的方法: