【问题标题】:Target tags in CSS, in Content-type application/xhtml+xml for earliers internet explorerCSS 中的目标标签,在 Content-type application/xhtml+xml 中用于早期的 Internet Explorer
【发布时间】:2013-06-23 13:15:27
【问题描述】:

下面我尝试在 CSS 中使用标记名(跨度)定位元素,但它在早期的 Internet Explorer 中不起作用...如果有人对此问题有解决方案,请帮助...

index.php

<?php header('Content-type: application/xhtml+xml'); ?>

<?xml-stylesheet type="text/xsl" href="copy.xsl"?>

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:aa="zz" xmlns:ee="rr">
<head>
    <title></title>
    <style type="text/css">
        /* it work */ aa\:span{background: #00ff00;}
        /* it doesnt work */ span{background: #00ff00;}
    </style>
</head>
<body>
    <aa:span id="span1">
        <aa:p>aaa</aa:p>
    </aa:span>
    <ee:span id="span1">
        <ee:p>aaa</ee:p>
    </ee:span>
</body>
</html>

复制.xsl

<stylesheet version="1.0"
     xmlns="http://www.w3.org/1999/XSL/Transform">
    <template match="/">
        <copy-of select="."/>
    </template>
</stylesheet>

【问题讨论】:

    标签: php internet-explorer xslt xhtml xml-namespaces


    【解决方案1】:

    你可以在没有命名空间的情况下将所有元素转换为纯 HTML,例如

    <xsl:template match="*">
      <xsl:element name="{local-name()}">
        <xsl:apply-templates select="@* | node()"/>
      </xsl:element>
    </xsl:template>
    

    那你还需要

    <xsl:template match="@* | comment() | text() | processing-instruction()">
      <xsl:copy/>
    </xsl:template>
    

    确保复制其他节点不变。

    这样你就得到了

    <xsl:stylesheet version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:template match="*">
          <xsl:element name="{local-name()}">
            <xsl:apply-templates select="@* | node()"/>
          </xsl:element>
        </xsl:template>
    
        <xsl:template match="@* | comment() | text() | processing-instruction()">
          <xsl:copy/>
        </xsl:template>
    
    </xsl:stylesheet>
    

    【讨论】:

    • 感谢您的反应,我只想提一下,我是 XSL 的新手,我将 copy.xsl 的内容替换为您答案的第一部分,但我不知道在哪里插入代码的第二部分(那么你还需要......)?或者一般如何应用您的回复?
    • 有人可以帮助并告诉我如何继续应用@Martin Honnen 发布的答案...?我是 XSL 的新手 :) 所以请耐心等待...
    • @kapsula,我已经编辑了我的答案,以便向您展示包含两个模板的完整样式表。
    • 首先谢谢,我会插入您发布的最后一个代码,它会向我发送一条消息(XML 解析错误:前缀未绑定到命名空间位置:*** 第 4 行,第 5 列: ---^
    • @kapsula,对不起,我从您的问题中复制了一些代码来完成样式表,但该部分与我的示例不匹配。现已更正。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    • 2014-11-30
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多