我对这个xslt很新,或者我很笨。请帮助。我有一个输入类型选择(下拉)有三个选项 - .Xml和xslt给出如下。我只是得到空白下拉。如何将所选值设置为下拉列表????。在我的情况下,一个下拉列表必须选择“仅查看”和另一个“完全访问”。 :(
<PagedResult xmlns="xxxxx/Object" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<RowCount>1</RowCount>
<PageCount>1</PageCount>
<Errors />
<ResultsPerPage>1</ResultsPerPage>
<CurrentPage>1</CurrentPage>
<Rows>
<SearchResultShare>
<ShareUserPrivilege>View Only</ShareUserPrivilege>
</SearchResultShare>
<SearchResultShare>
<ShareUserPrivilege>Full Access</ShareUserPrivilege>
</SearchResultShare>
</Rows>
</PagedResult>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pg="xxxxx/Object">
<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" indent="no"/>
<xsl:decimal-format name="us" NaN="n/a"/>
<pg:options>
<option>Select</option>
<option>Full Access</option>
<option>View Only</option>
</pg:options>
<xsl:variable name="options" select="document('')//pg:options/*"/>
<xsl:template match="/pg:PagedResult">
<xsl:choose>
<xsl:when test="pg:Errors/node()">
<ul>
<xsl:apply-templates select="pg:Errors"/>
</ul>
</xsl:when>
<xsl:when test="pg:RowCount = 0">
<div class="tableBorderColorBGrnd tableBorderColor tableHeader">
<table class="primaGridViewSmall" cellspacing="0" cellpadding="1" border="0" width="100%">
<tr valign="bottom">
<th style="width: 3%;text-align: left;"></th>
</tr>
</table>
</div>
<table class="primaGridViewSmall" cellspacing="0" cellpadding="1" border="0" width="100%">
<tr>
<td style="padding: 3px;">Your search did not return any share users.</td>
</tr>
</table>
</xsl:when>
<xsl:otherwise>
<div class="tableBorderColorBGrnd tableBorderColor tableHeader">
<table id="tblSearchResultsHeader" class="primaGridViewSmall" cellspacing="0" cellpadding="1" border="0" width="100%">
<tr valign="bottom">
<th style="width: 3%;text-align: left;"></th>
</tr>
</table>
</div>
<div id="searchResultsTable" class="resultsContainer1">
<table id="tblSearchResults" class="primaGridViewSmall" cellspacing="0" cellpadding="1" border="0" width="100%">
<xsl:apply-templates select="pg:Rows"/>
</table>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="pg:SearchResultShare">
<tr>
<td style="width: 10%;text-align: left;">
<xsl:variable name="ShareUserPrivilege" select="pg:ShareUserPrivilege"/>
<select id="ShareUserPrivilege">
<xsl:for-each select="$options">
<option value="{.}">
<xsl:if test=". = $ShareUserPrivilege">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
<xsl:value-of select="."/>
</option>
</xsl:for-each>
</select>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
<div xmlns:pg="xxxxx/Object" class="tableBorderColorBGrnd tableBorderColor tableHeader"><table id="tblSearchResultsHeader" class="primaGridViewSmall" cellspacing="0" cellpadding="1" border="0" width="100%">
<tr valign="bottom"><th style="width: 3%;text-align: left;"></th></tr>
</table>
</div><div xmlns:pg="xxxxx/Object" id="searchResultsTable" class="resultsContainer1">
<table id="tblSearchResults" class="primaGridViewSmall" cellspacing="0" cellpadding="1" border="0" width="100%">
<tr><td style="width: 10%;text-align: left;"><select id="ShareUserPrivilege">
</select></td>
</tr>
<tr><td style="width: 10%;text-align: left;"><select id="ShareUserPrivilege">
</select></td>
</tr>
</table></div>
页面加载时,“ShareUserPrivilege”例如:仅查看,从数据库中选择值用户。因此,在页面加载时,我需要将下拉选择的索引设置为该值,即“完全访问”的内容“选择”。目前,未设置所选值的值始终为“&lt; - Select - &gt;”。
Eg:
<--Select--> selected index -1
View Only selected index 0
Full Access selected index 1
在编辑页面用户已经选择说“完全访问”选择索引是1并且我已将所选索引值1存储到db.So现在在列表页面(或查看页面)中我需要列出这些结果。下拉列表必须设置为“完全访问权限”。如何?
output needed
Full Access selected index 1
<--Select-> selected index -1
View Only selected index 0
答案 0 :(得分:0)
您正在尝试生成<option selected="true"/>
。事实上,HTML代码<option selected>
是<option selected="selected"/>
的SGML简写。所以只需更改代码即可生成。
答案 1 :(得分:0)
答案是
<select name="select2" id="select2" groupID="{pg:ShareGroupID}" onchange="javascript:editedGroupPrivilegeChanges('{pg:ShareGroupID}',this);return false;">
<xsl:if test="pg:ShareGroupPrivilege='View Only'">
<option value="0" selected="true">View Only</option>
<option value="1">Full Access</option>
</xsl:if>
<xsl:if test="pg:ShareGroupPrivilege='Full Access'">
<option value="0">View Only</option>
<option value="1" selected="true">Full Access</option>
</xsl:if>
</select>