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
Xslt XSL:将单引号和双引号替换为&;载脂蛋白;及;引用;_Xslt_Xslt 1.0 - Fatal编程技术网

Xslt XSL:将单引号和双引号替换为&;载脂蛋白;及;引用;

Xslt XSL:将单引号和双引号替换为&;载脂蛋白;及;引用;,xslt,xslt-1.0,Xslt,Xslt 1.0,我有一个XSL,用于将一个XML转换为另一个,如: <xsl:value-of select="somestatement"/> 有人能提出解决方案吗 提前感谢您的帮助。您需要为此调用一个命名的递归模板。尝试: <xsl:template name="escape-quotes"> <xsl:param name="text"/> <xsl:param name="searchString">'</xsl:param>

我有一个XSL,用于将一个XML转换为另一个,如:

<xsl:value-of select="somestatement"/>
有人能提出解决方案吗


提前感谢您的帮助。

您需要为此调用一个命名的递归模板。尝试:

<xsl:template name="escape-quotes">
    <xsl:param name="text"/>
    <xsl:param name="searchString">'</xsl:param>
    <xsl:param name="replaceString">&amp;apos;</xsl:param>
    <xsl:variable name="apos">'</xsl:variable>  
    <xsl:choose>
        <xsl:when test="contains($text,$searchString)">
            <xsl:call-template name="escape-quotes">
                <xsl:with-param name="text" select="concat(substring-before($text,$searchString), $replaceString, substring-after($text,$searchString))"/>
                <xsl:with-param name="searchString" select="$searchString"/>
                <xsl:with-param name="replaceString" select="$replaceString"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:when test="$searchString=$apos">
            <xsl:call-template name="escape-quotes">
                <xsl:with-param name="text" select="$text"/>
                <xsl:with-param name="searchString">"</xsl:with-param>
                <xsl:with-param name="replaceString">&amp;quot;</xsl:with-param>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$text" disable-output-escaping="yes"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

'
&;载脂蛋白;
'  
"
&";
调用模板的示例:

<output>
    <xsl:call-template name="escape-quotes">
        <xsl:with-param name="text">This is an "example" string. I have 'single quotes'.</xsl:with-param>
    </xsl:call-template>
</output>

这是一个“示例”字符串。我有“单引号”。
结果:

<output>This is an &quot;example&quot; string. I have &apos;single quotes&apos;.</output>
这是一个“示例”字符串。我有单引号;。

我不理解这个问题。单引号(
)在XML中表示为
,双引号(
)表示为
。不需要任何替换。@LingamurthyCS的可能副本:由于与供应商的某种协议,我们必须将XML与&apos;和“而不是”一起装运,并且我仍然得到输出:这是一个“示例”字符串。我有“单引号”。
<output>This is an &quot;example&quot; string. I have &apos;single quotes&apos;.</output>