0

私はこのxsltに非常に慣れていないか、愚かです.助けてください.3つのオプションを持つ入力タイプの選択(ドロップダウン)があります.Xmlとxsltを以下に示します.空白のドロップダウンしか取得していません.選択したものを設定する方法値をドロップダウンに ????.ここでは、1 つのドロップダウンで「表示のみ」を選択し、別の「フルアクセス」を選択する必要があります。:(

XML

<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>

XSLT

 <?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」の例: 表示のみ、データベースから選択された値のユーザーを持っています。そのため、ページの読み込み時に、ドロップダウンの選択したインデックスをその値に設定する必要があります。つまり、「選択」ではなく「フルアクセス」です。 . 現在、選択された値は常に「<--Select-->」として設定されていません。

Eg:
    <--Select-->    selected index -1
    View Only       selected index 0
    Full Access     selected index 1

ユーザーが既に選択した編集ページで、「フルアクセス」と選択したインデックスは 1 であり、選択したインデックス値 1 を db に保存しました。ダウンは「フルアクセス」に設定する必要があります。どのように?

output needed

   Full Access     selected index 1
   <--Select->     selected index -1
   View Only       selected index 0
4

2 に答える 2

0

を生成しようとしています<option selected="true"/>。実際、HTML コード<option selected>は の SGML 短縮形です<option selected="selected"/>。したがって、コードを変更してそれを生成するだけです。

于 2013-06-24T13:13:34.787 に答える