【发布时间】:2016-04-19 22:30:05
【问题描述】:
嗨,任何了解 xslt 的人都可以帮助我。 我只想显示复选框,如果有值复选框必须选中,否则不选中。我使用了选择,但它没有给我想要的东西。它只给了我一个选中的复选框。
这是我的 C# 代码
public DataSet printIST(long Id)
{
var query0 = (from request in _entities.ISTMotivations
select new
{
ISTID = request.ISTID,
ISTMotivation = request.ISTReason.LookupDesc,
ISTMotivationID = request.ISTMotivationID,
ISTReasonID = request.ISTReasonID
}).OrderBy(x => x.ISTReasonID);
var query2 = (from request in _entities.ISTMotivations
where request.ISTID==Id
select new
{
ISTMotivationID=request.ISTMotivationID,
ISTID=request.ISTID,
ISTReasonID=request.ISTReasonID
}).OrderBy(x=>x.ISTReasonID);
DataSet ds = new DataSet();
ds.Tables.Add(query0.CopyToDataTable()); ds.Tables[0].TableName = "Table4";
ds.Tables.Add(query2.CopyToDataTable()); ds.Tables[1].TableName = "Table5";
return ds;
}
这是我的 XSLT 代码
<?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" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:key name ="keyMoticationID" match ="NewDataSet/Table4" use ="ISTMotivationID"/>
<xsl:key name ="keycheck" match ="NewDataSet/Table5" use ="concat(ISTID, '+',ISTMotivationID)"/>
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<html>
<xsl:variable name="lst4" select="//NewDataSet/Table4" />
<xsl:variable name="lst5" select="//NewDataSet/Table5" />
<style>
TABLE {empty-cells: show; border-spacing: 0px; margin: 0px; padding: 0px;width:100%;}
.pagebreak {page-break-after: always;}
TD.HeaderText {font-family:Arial;font-size:14pt;border:0;margin:0;background:none;font-weight:bold;}
TR.HeaderText {font-family:Arial;font-size:14pt;border:0;margin:0;background:none;font-weight:bold;}
TR.NormalText {font-family:Arial;font-size:10pt;border:0;margin:0;background:none;font-weight:normal;}
TD.NormalText {font-family:Arial;font-size:10pt;border:0;margin:0;background:none;font-weight:normal;}
TABLE.SpacedRows TD {padding:2pt 0 8pt 0; vertical-align:top;}
TABLE.NormalText {font-family:Arial;font-size:10pt;border:0;margin:0;background:nonkeyIDe;font-weight:normal;}
</style>
<title>
<center>Application for IST transfer</center>
</title>
<table border="1" cellspacing="0" cellpadding="0" width="100%" style="border-style:solid;border-color:Black;border-width:1px;font-family:Arial;border-collapse: collapse;font-size:11px;" >
<xsl:for-each select="$lst4[generate-id(.) = generate-id(key('keyMoticationID', ISTMotivationID)[1])]">
<xsl:variable name="intISTMotivationID">
<xsl:value-of select="ISTMotivationID" />
</xsl:variable>
<tr>
<td style="width:2%; padding:2px;text-align:center;">
<xsl:value-of select ="$lst4[ISTMotivationID=$intISTMotivationID]/ISTReasonID"/>
</td>
<td style="width:96%; padding:2px;">
<xsl:value-of select ="$lst4[ISTMotivationID=$intISTMotivationID]/ISTMotivation"/>
</td>
<xsl:for-each select="$lst5[generate-id(.) = generate-id(key('keycheck',concat(ISTID,'+', $intISTMotivationID))[1])]">
<xsl:variable name="intISTID">
<xsl:value-of select="ISTID" />
</xsl:variable>
<xsl:choose>
<xsl:when test="$lst5[ISTID=$intISTID and ISTMotivationID=$intISTMotivationID]/ISTReasonID">
<td valign="top" style="width:2%; padding:3px; text-align:center;">
<input id="chkISTReasonID" name="ISTReasonID" type="checkbox" checked="checked"></input>
</td>
</xsl:when>
<xsl:otherwise>
<td valign="top" style="width:2%; padding:3px;text-align:center;">
<input id="chkISTReasonID" name="ISTReasonID" type="checkbox"></input>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</html>
</fo:root>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
-
<xsl:choose ... >是你所追求的,但不知道你是如何尝试使用它的,很难知道为什么你不能让它工作。 -
@AdrianWragg 我不知道为什么不显示未选中的复选框
-
显而易见的答案是,这是因为您的测试始终返回 true - 该节点存在。不幸的是,这里没有足够的信息来复制这个问题。尝试将其重写为演示问题的最小可能方式 - 删除大量不相关的代码,包括 XML 等。
-
您没有看到其他复选框的原因显然是因为您的测试条件是真实的!
-
@Dlamini.M 请发布一个 reproducible 示例,包括 XML 输入 - 最好将其最小化为重现问题所必需的内容。见:minimal reproducible example