嗨,任何了解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>
答案 0 :(得分:0)
问题解决我刚刚在查询中执行了左连接并且它正常工作。
var query2 = (from a in _entities.ISTReasons
join b in _entities.ISTMotivations on new { col1 = a.ISTReasonID, col2 = Id } equals new { col1 = b.ISTReasonID, col2 = b.ISTID }
into tmp1
from c in tmp1.DefaultIfEmpty()
select new
{
ISTReasonID = a.ISTReasonID,
ReasonDesc = a.LookupDesc,
ReasonCode = a.LookupCode,
Checked = c.ISTMotivationID != null ? "Y" : "N"
});