CSS中的目标标记,在早期internet explorer的内容类型application/xhtml+xml中


Target tags in CSS, in Content-type application/xhtml+xml for earliers internet explorer

下面我尝试在CSS中使用标记名(span)来定位元素,但它在早期的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>

好吧,您可以将所有元素转换为纯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>