如何解决基于日期的XSLT条件CSS
当前具有以下结构:
<? xml version = "1.0" encoding = "utf-8"?>
<xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" xmlns: msxsl = "urn: schemas-microsoft-com: xslt">
<xsl: template match = "/">
<table border = "1" class = "TxtRis">
<Tr>
<th class = "LinkPopup"> Name </th>
<th class = "LinkPopup"> Date </th>
</ Tr>
<Xsl: apply-templates />
</ Table>
</ Xsl: template>
<xsl: template match = "Data / *">
<tr align = "center">
<td width = "50%" class = "DescrBox">
<xsl: value-of select = "name" />
</ Td>
<td width = "50%" class = "DescrBox">
<xsl: value-of select = "date" />
</ Td>
</ Tr>
</ Xsl: template>
</ Xsl: stylesheet>
我不想再使用“ DescrBox”,而是使用基于select =“ date”中获得的值的类条件。
If date> = (getdate () + 7)-14 then
class = "LegImg LegImgExpired6 LegImgStato"
otherwise
class = "LegImg LegImgAtt LegImgStato"
.LegImg Expired6 {
background-color: red;
}
.LegImgStato {
margin-left: 10px;
}
.LegImg {
width: 1.4em;
height: 1.4em;
margin-right: 20px;
border-radius: 10px;
float: left;
border: 1px solid # 999999;
.LegImgAtt {
background-color: lawngreen;
}
.LegImgStato {
margin-left: 10px;
}
.LegImg {
width: 1.4em;
height: 1.4em;
margin-right: 20px;
border-radius: 10px;
float: left;
border: 1px solid # 999999;
我不能使用js或php 你能帮我处理一下病吗?
谢谢
解决方法
contains()函数返回true是第一个参数包含第二个参数。
<xsl:if test="contains(date,'#')" />date does contain #</xsl:if>
<xsl:if test="not(contains(date,'#'))" />date does not contain #</xsl:if>
在XSL中,您可以将结果直接插入CSS类中,如下所示:
<td width = "50%" class = "{contains(date,'#')}_class">
将产生此HTML输出
<td width = "50%" class = "true_class">
或
<td width = "50%" class = "false_class">
然后您可以在CSS中定义要显示的类名称,但是您希望它们显示:
.true_class{
background-color: red;
}
.false_class{
background-color: lawngreen;
}
此外,您将遇到问题
<xsl: template ... />
应删除空格:
<xsl:template ... />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。