同时更改HTML和嵌入式XML的样式

时间:2013-01-23 22:09:09

标签: html css xml

我有一些HTML5文件,我通过 object 元素嵌入XML。现在,对于HTML文件,我有备用样式表。我想要做的是在HTML的同时更改嵌入式XML的样式(因为XML文件有自己的样式表)。因此,当我在浏览器的帮助下为HTML页面选择样式时,我希望也改变XML的样式。有没有办法做到这一点?

HTML:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>LondonDiamond Restaurant Menu</title>
    <meta charset="UTF-8" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" media="screen" title="Standard red black white"/>
    <link rel="stylesheet" type="text/css" href="../css/style_print.css" media="print" title="Print"/>
    <link rel="alternate stylesheet" type="text/css" href="../css/alt_style.css" media="screen" title="Monochrome"/>
</head>
<body>
    <object data="../xml/menu.xml"><span></span></object>
</body>
</html>

XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="../css/style4xml.css"?>
<!DOCTYPE menu SYSTEM "../dtd/menu.dtd">

<menu>
     irrelevant
</menu>

当我为HTML选择备用样式表时,颜色会发生变化,但嵌入式XML保持相同的颜色(这是正常的)但我也想在HTML中同时更改它。

1 个答案:

答案 0 :(得分:0)

我所做的是为HTML文件和XML文件应用相同的默认和替代样式表。在CSS文件中,我有HTML和XML元素的样式。

HTML:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>LondonDiamond Restaurant Menu</title>
    <meta charset="UTF-8" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" media="screen" title="Red Black White"/>
    <link rel="stylesheet" type="text/css" href="../css/style_print.css" media="print"/>
    <link rel="alternate stylesheet" type="text/css" href="../css/altstyle.css" media="screen" title="Monochrome"/>
</head>
.......
</html>

XML:

 <?xml version="1.0" encoding="UTF-8"?>
 <?xml-stylesheet type="text/css" href="../css/style.css" title="Red Black White"?>
 <?xml-stylesheet type="text/css" href="../css/altstyle.css" alternate="yes" title="Monochrome"?>
 <!DOCTYPE menu SYSTEM "../dtd/menu.dtd">

 <menu>
      .....
 </menu>

CSS:

body {...}
header {...}
...
menu {...}