0
我想要改造這個類型的XML調色板文件:使用此XSL轉換變換調色板文件的HTML內容使用XSLT
<?xml version="1.0"?>
<?xml-stylesheet href="Palette.xsl" type="text/xsl"?>
<Palette Name="MyPalette">
<PaletteEntry Color="#D0427B" Color2="#D0427B" />
<PaletteEntry Color="#D55588" Color2="#D55588" />
<PaletteEntry Color="#DA6895" Color2="#DA6895" />
</Palette>
:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Palette">
<html>
<head>
<title>Palette {@Name}</title>
<!--link rel="stylesheet" href="Palette.css" type="text/css"/-->
</head>
<body>
<div class="palette">
<xsl:apply-templates/>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="PaletteEntry">
<div class="palette-entry" style="width:40px;height:40px; margin:2px; float:left; background-color: {@Color}; border: 2px solid {@Color2};">
<xsl:apply-templates select="@*"/>
</div>
</xsl:template>
<xsl:template match="@Color">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="@Color2">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
在輸出的問題是,顏色屬性在屬性中時呈現良好,但未在內容中翻譯。下面是HTML輸出:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Palette {@Name}</title>
</head>
<body>
<div class="palette">
<div class="palette-entry" style="width:40px;height:40px; margin:2px; float:left; background-color: #495359; border: 2px solid #495359;" color="495359" color2="#495359"></div>
<div class="palette-entry" style="width:40px;height:40px; margin:2px; float:left; background-color: #5B646A; border: 2px solid #5B646A;" color="5B646A" color2="#5B646A"></div>
</div>
</body>
</html>
我怎樣才能顏色值複製到內容?
預期輸出:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Palette "MyPalette"</title>
</head>
<body>
<div class="palette">
<div class="palette-entry" style="width:40px;height:40px; margin:2px; float:left; background-color: #495359; border: 2px solid #495359;">#495359<br/>#495359</div>
<div class="palette-entry" style="width:40px;height:40px; margin:2px; float:left; background-color: #5B646A; border: 2px solid #5B646A;">#5B646A<br/>#5B646A</div>
</div>
</body>
</html>
可以告訴你,你居然想到在這種情況下,輸出?謝謝 –