1

我有如下的 XML 节点 -

<url title="Take the STARPLUS® for entertaiment" depth="2" is_external="False"/>

现在在 XSLT 中,我正在编写如下代码 -

<xsl:when test="contains(@title,'®')">

<!-- Make registration mark super scripted-->
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@title"/>
</xsl:otherwise>     
</xsl:choose>

由于特殊字符,这里contains(@title,'®')看起来不起作用。

有人可以帮我写这个 XSLT 检查。

注意-我不能在 XML 中进行编码或转义,因为它已经在系统中到位。

谢谢

4

1 回答 1

0

该测试应该可以正常工作。您可以尝试使用实体引用:

contains(@title,'&#174;')

这是两个正确匹配的示例。

XML 输入

<url title="Take the STARPLUS® for entertaiment" depth="2" is_external="False"/>

XSLT 1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="url">
        <xsl:if test="contains(@title,'®')">
            <has_reg><xsl:value-of select="@title"/></has_reg>
        </xsl:if>
        <xsl:if test="contains(@title,'&#174;')">
            <has_reg><xsl:value-of select="@title"/></has_reg>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>

输出

<has_reg>Take the STARPLUS® for entertaiment</has_reg>
<has_reg>Take the STARPLUS® for entertaiment</has_reg>
于 2013-11-13T07:48:49.037 回答