How do I escape a character in XSLT

試著忘記壹切 提交于 2019-12-10 14:17:29

问题


I have an XSLT that transforms a XML to PLSQL

I need to escape the character: > (greater than)

ex:

P_C710_INT_PROFILE_ID =>

I tried using > and putting the character in xsl:text with no luck

Any ideas?

Thanks


回答1:


Thank everyone but the correct answer is this:

<xsl:text disable-output-escaping="yes">&gt;</xsl:text>



回答2:


There is no problem. This stylesheet (empty):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
</xsl:stylesheet>

Input:

<text>P_C710_INT_PROFILE_ID =&gt;</text>

Output:

P_C710_INT_PROFILE_ID =>

EDIT: Because your question is not clear, I'm adding a solution in case you want to output character entity under a xsl:output/@method="text" declaration.

This stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>
    <xsl:template match="text()" name="text">
        <xsl:param name="text" select="."/>
        <xsl:if test="$text != ''">
            <xsl:variable name="first" select="substring($text,1,1)"/>
            <xsl:choose>
                <xsl:when test="$first = '&gt;'">&amp;gt;</xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$first"/>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:call-template name="text">
                <xsl:with-param name="text" select="substring($text,2,(string-length($text)-1) div 2 + 1)"/>
            </xsl:call-template>
            <xsl:call-template name="text">
                <xsl:with-param name="text" select="substring($text,(string-length($text)-1) div 2 + 3)"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

Output:

P_C710_INT_PROFILE_ID =&gt;

This relate to Render escaped XML on browser




回答3:


I was struggling with this as well and even after changing the output method and adding the disable-output-escaping attribute and it still wasnt working.

Then i looked in my source code and i realized that i was using an XmlTextWriter with the results of the transform and the XmlTextWriter was applying the output escaping. Once i switched it to just use a StringWriter the output was correct.



来源:https://stackoverflow.com/questions/3415728/how-do-i-escape-a-character-in-xslt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!