【问题标题】:Output php processing instruction inside attribute value输出属性值内的php处理指令
【发布时间】:2017-11-07 17:40:50
【问题描述】:

在我的 XSLT(2.0 - 输出方法是 html)中,我有这个:

<img>
    <xsl:attribute name="href">
        <xsl:text disable-output-escaping="yes">&lt;?php echo get_url(); ?&gt;</xsl:text>
    </xsl:attribute>
</img>

我想要的输出如下:

<img href="<?php echo get_url(); ?>">

我得到的输出如下:

<img href="<?php echo get_url(); ?&gt;">

尝试了很多不同的方法来让 ">" 出现在输出中,而不是 > (CDATA 标记的部分等)但似乎没有任何效果。奇怪的是小于号可以正常工作,但大于号不行。我正在使用 Saxon-PE 9.5.1.7。

【问题讨论】:

    标签: html xslt xslt-2.0 processing-instruction


    【解决方案1】:

    将字符映射与其他地方不需要的一些字符一起使用,这是一个改编自 XSLT 2.0 规范的示例 (https://www.w3.org/TR/xslt20/#character-maps):

    <img href="«?php echo get_url(); ?»"/>
    

    <xsl:output method="html" use-character-maps="m1"/>
    
    <xsl:character-map name="m1">
        <xsl:output-character character="«" string="&lt;"/>
        <xsl:output-character character="»" string="&gt;"/>
    </xsl:character-map>
    

    在线示例位于http://xsltransform.net/93dEHFP

    至于禁用输出转义,据我所知,它不适用于属性值,您得到的结果不是禁用输出转义的结果,而只是使用xsl:output method="html"(@987654323 @) 强制“HTML 输出方法不得转义出现在属性值中的“

    【讨论】:

    • 很棒的伙伴-非常感谢您的帮助。 K
    猜你喜欢
    • 2013-06-11
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    • 1970-01-01
    • 2013-10-26
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多