Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml XSLT1.0可以’;不要翻译撇号_Xml_Xslt_Apostrophe - Fatal编程技术网

Xml XSLT1.0可以’;不要翻译撇号

Xml XSLT1.0可以’;不要翻译撇号,xml,xslt,apostrophe,Xml,Xslt,Apostrophe,我的XML中包含以下内容: <MyElement> Cats&amp;apos; eyes </ MyElement > 但是我想 Cats’ eyes 我试过了 <xsl:value-of select='translate(MyElement, "&amp;apos; ", "&apos; ")' /> 但是它不起作用,结果是一些字符被删除了 有什么想法吗 谢谢您的第一个问题是您的内容似乎被“双重转义”。撇号的实体是&a

我的XML中包含以下内容:

<MyElement> Cats&amp;apos; eyes </ MyElement >
但是我想

Cats’ eyes
我试过了

<xsl:value-of select='translate(MyElement, "&amp;apos; ", "&apos; ")'  />

但是它不起作用,结果是一些字符被删除了

有什么想法吗


谢谢

您的第一个问题是您的内容似乎被“双重转义”。撇号的实体是
&apos,而不是
&;载脂蛋白

尝试用替换字符无效,因为它的工作方式与您预期的不同。它不是查找/替换方法。在第二个参数中指定字符列表,然后在第三个参数中指定要将每个字符转换为的相应字符。如果第三个参数中的字符列表中没有相应的字符,则会将其删除

您将需要使用来执行字符替换

例如:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="MyElement"/>
            <xsl:with-param name="replace" select="'&amp;apos;'"/>
            <xsl:with-param name="with" select='"&apos;"'/>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="replace-string">
        <xsl:param name="text"/>
        <xsl:param name="replace"/>
        <xsl:param name="with"/>
        <xsl:choose>
            <xsl:when test="contains($text,$replace)">
                <xsl:value-of select="substring-before($text,$replace)"/>
                <xsl:value-of select="$with"/>
                <xsl:call-template name="replace-string">
                    <xsl:with-param name="text"
                        select="substring-after($text,$replace)"/>
                    <xsl:with-param name="replace" select="$replace"/>
                    <xsl:with-param name="with" select="$with"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$text"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

当然,使用XSLT 2.0,您可以只使用以下函数:

<xsl:sequence select='replace(MyElement, "&amp;apos;", "&apos;")'/>

很简单,只需添加
禁用输出转义=“yes”



aw,赶快完成。我只是复制并粘贴了他的示例,但仍然得到了输入的文本节点(而不是他声称的输出)。对不起。顺便问一下,实际的字符是撇号还是正确的单引号?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="MyElement"/>
            <xsl:with-param name="replace" select="'&amp;apos;'"/>
            <xsl:with-param name="with" select='"&apos;"'/>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="replace-string">
        <xsl:param name="text"/>
        <xsl:param name="replace"/>
        <xsl:param name="with"/>
        <xsl:choose>
            <xsl:when test="contains($text,$replace)">
                <xsl:value-of select="substring-before($text,$replace)"/>
                <xsl:value-of select="$with"/>
                <xsl:call-template name="replace-string">
                    <xsl:with-param name="text"
                        select="substring-after($text,$replace)"/>
                    <xsl:with-param name="replace" select="$replace"/>
                    <xsl:with-param name="with" select="$with"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$text"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
<xsl:sequence select='replace(MyElement, "&amp;apos;", "&apos;")'/>
<xsl:value-of select="MyElement" disable-output-escaping="yes"/>