gpt4 book ai didi

html - 如何在 XML 上同时使用 CSS 和 XSLT?

转载 作者:太空宇宙 更新时间:2023-11-04 06:11:12 24 4
gpt4 key购买 nike

我正在尝试将我的 CSS 样式表与我的 XML 一起使用,它也附加了一个 XSLT 样式表,这导致它在 CSS 附加到一个巨大的 block 中时完全超出其格式。

链接 CSS 样式表并在聊天中尝试其样式以使其格式化。

XML

       <?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="cuisinexsl.xsl"?>
<?xml-stylesheet type="text/css" href="ofd.css"?>


<cuisines>
<cuisinetype>
<cuisine>Greek</cuisine>
<name>Food from Zeus</name>
<address>96 Almighty Road</address>
<phone>02 2321 5592</phone>
<deliveryfee>Delivery fee is $7</deliveryfee>
<URL>https://zeusfoods.com.au/</URL>
<takeaway>Yes</takeaway>
<dinein>Yes</dinein>
<openhours>9-5 Mon-Sat,Sunday Closed</openhours>
<description>Food created by us, that even the almighty would
die for.</description>
</cuisinetype>
</cuisines>

XSLT

   <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:stylesheet type="text/css" href="ofd.css">

<xsl:template match="/">
<html>
<body>
<h1>Cuisine Restaurants</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="cuisinetype">
<xsl:for-each select="cuisines/cuisinetype">
<xsl:sort select="name"/>
</xsl:for-each>
<p>
<xsl:apply-templates select="cuisine"/>
<xsl:apply-templates select="name"/>
<xsl:apply-templates select="address"/>
<xsl:apply-templates select="phone"/>
<xsl:apply-templates select="deliveryfee"/>
<xsl:apply-templates select="URL"/>
<xsl:apply-templates select="takeaway"/>
<xsl:apply-templates select="dinein"/>
<xsl:apply-templates select="openhours"/>
<xsl:apply-templates select="description"/>
</p>
</xsl:template>

<xsl:template match="cuisine">
Cuisine type: <span style="">
<xsl:value-of select="."/></span>
<br />
</xsl:template>


</xsl:stylesheet>


CSS

这是css,这就像重写xslt,

  body {
background-color: lightpink;
}

h1 {
color: black;
text-shadow: 3px 2px grey;
font-size: 60px;
text-align: center;
}

h2 {
color: black;
margin-left: 20px;
text-decoration: underline;
text-transform: uppercase;
text-align: center;
font-size: 35px;
text-shadow: 2px 1px grey;
}

h3 {
color: black;
font-size: 25px
}

h4 {
color: black;
margin-left: 20px;
margin-right: 20px;
font-family: "Times New Roman", Times, serif;
text-align: center;
}

body {
background-image: url("Graphics/background2.jpg");
}

#para1 {
text-align: center;
color: red;
}

.lightgrey {
background-color: lightgrey;
}

.padding {
border: 3px solid black;
padding: 1px 125px 1px 125px;
background-color: grey;
}

.footer {
border: 3px solid black;
padding: 1px 125px 1px 125px;
background-color: grey;
}

div.picture {
border: 2px solid #000000;
width: 600px;
height: 4oopx
}

div.picture:hover {
border: 2px solid #000000;
}

div.picture img {
width: 100%;
height: auto;
}

div.imagedescription {
padding: 2px;
text-align: centre;
background-color: lightgrey;
}

.site-info::after {
content: "Copyright Hisham Echafaki 2017 - All Rights Reserved ";
}

.parastyle1 {
font-family: Arial, Helvetica, sans-serif;
color: black;
font-size: 28px;
font-weight: bold;
}

.parastyle2 {
font-family: Arial, Helvetica, sans-serif;
color: black;
font-size: 20px;
font-weight: bold;
}

.box {
position: relative;
}

.yeet_time {
position: absolute;
bottom: 0;
right: 0;
}

p {
margin-left: 150px;
margin-right: 150px;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
color: black;
font-weight: bold;
}

pw {
margin-left: 20px;
font-family: Arial, Helvetica, sans-serif;
font-size: 40px;
color: white;
font-weight: bold;
}

pw2 {
margin-left: 20px;
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;
color: white;
font-weight: bold;
}

pw3 {
font-family: Arial;
color: black;
font-size: 20px;
font-weight: bold;
margin-left: 40px;
margin-right: 40px;
}

pw4 {
font-family: Arial;
color: black;
font-size: 20px;
font-weight: bold;
margin-left: 150px;
margin-right: 0px;
}

pw5 {
margin-left: 880px;
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;
color: black;
font-weight: bold;
}

pw6 {
font-family: Arial;
color: black;
font-size: 20px;
font-weight: bold;
margin-left: 275px;
margin-right: 0px;
}

a:link {
color: blue;
background-color: transparent;
text-decoration: none;
}

a:visited {
color: aqua;
background-color: transparent;
text-decoration: none;
}

a:hover {
color: navy;
background-color: transparent;
font-size: 23px;
}

a:active {
color: fuchsia;
background-color: transparent;
text-decoration: underline;
}

h5 {
color: black;
margin-left: 40px;
text-decoration: underline;
text-transform: uppercase;
text-align: left;
font-size: 35px;
text-shadow: 2px 1px grey;
}

a.zoom:hover {
transform: scale(1.5);
/* (150% zoom - Note: if the zoom is too large, it will go outside of the viewport) */
}

</style> <div class="a"></div> margin1 {
margin-left: 1cm;
}

最佳答案

写在注释中有点太长了,但是像您所做的那样将 XML 链接到 XSLT 样式表和 CSS 样式表是没有意义的

<?xml-stylesheet type="text/xsl" href="cuisinexsl.xsl"?>
<?xml-stylesheet type="text/css" href="ofd.css"?>

但是,在您的情况下,您并没有尝试使用 CSS 设置 XML 的样式,而是使用 XSLT 创建的 HTML。

在这种情况下,您需要执行以下操作

  1. 删除 <?xml-stylesheet type="text/css" href="ofd.css"?>来自 XML
  2. 移除流氓<xsl:stylesheet type="text/css" href="ofd.css">来自 XSLT(因为否则您的 XSLT 将不会格式正确)。
  3. 添加行 <link rel="stylesheet" type="text/css" href="ofd.css" /><head> HTML 部分

例如:

<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="ofd.css" />
</head>
<body>
<h1>Cuisine Restaurants</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

关于html - 如何在 XML 上同时使用 CSS 和 XSLT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56395127/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com