0

現在、次の XSLT ファイルがあります。

  <xsl:template match="/">
    <html>
      <head>

      </head>
      <body>
        <input type="text" id="txtSearch"/>
        <input type="submit" name="btnSearch" value="Search" onclick="" />

        <br />
        <br />
        <!-- Call to the procedure/function -->
        <xsl:apply-templates select="CommercialClients">
        </xsl:apply-templates>        
      </body>
    </html>
  </xsl:template>

  <!-- Procedure/function -->
  <!-- Loop through each AClient and retrieve CompanyName-->
  <xsl:template match="CommercialClients">
    <xsl:for-each select="AClient[starts-with(CompanyName,'L')]">
      <xsl:sort select="CompanyName" order="ascending"/>
        <xsl:value-of select="CompanyName"/>
        <br />
    </xsl:for-each>
  </xsl:template>

また、次のような XML ドキュメントもあります。

<CommercialClients>
<AClient>
<ClientNo>1813</ClientNo><CompanyName>K Plastics</CompanyName><FullAddress>
  <Address>Cleveragh Industrial Estate </Address>
  <Town>SLIGO</Town>
  <Country>IRELAND</Country>
  <PostCode>00353 7166</PostCode>
</FullAddress><TelephoneNo/>
</AClient>

私の問題:ユーザーがボタンをクリックすると、テキストボックスからユーザーの入力を取り込み、データをフィルタリングして表示するように、作成したボタンを使用したいと考えています。

したがって、ユーザーがテキストボックス「L」に入力すると、文字「L」で始まる企業のみが表示されます。現時点では、「L」が付いている会社のみを表示するようにハード コードされており、ユーザー定義にする方法がわかりません。

助けやアイデアはありますか?これが ASPX ファイルですが、これらすべてを使用してフィルターを編集する方法がわかりません。

//from the request object get the value of the filter
string AFilter = Request.QueryString["txtFilter"];
//if there is no filter
if (AFilter == null)
{
    //make the filter a blank string (a null value will crash the program)
    AFilter = "";
}
//create an instance of the XML Conduit class passing the name of the xml file to the constructor
MyClassLibrary.clsXMLConduit MyXMLConduit = new MyClassLibrary.clsXMLConduit("commercial.xml");
//add a parameter to filter the data on company name
MyXMLConduit.AddParameter("CompanyFilter", AFilter);
//perform the transformation using the xslt file commercial.xslt
MyXMLConduit.Execute("commercial.xslt");
//set the character set encoding for the output stream
Response.Charset = "UTF-8";
//output the transformed document to the requesting browser
Response.Write(MyXMLConduit.TransformedOutput);
4

1 に答える 1

1

ASP.Net コードでは、少なくともフィルター値をパラメーターとして XSLT に渡しているようです。

MyXMLConduit.AddParameter("CompanyFilter", AFilter); 

その場合、XSLT 自体の中でパラメーターを宣言する必要があります。これは、xsl:template 要素の外側の XSLT スタイルシートの上部に配置されます。

<xsl:param name="CompanyFilter" />

必要に応じて、デフォルト値を指定できます

<xsl:param name="CompanyFilter" select="'L'" />

次に、ハードコーディングを行う代わりにそれを使用するには、通常の変数 ($symbol で始まる) を使用するのと同じようにします。

<xsl:for-each select="AClient[starts-with(CompanyName, $CompanyFilter)]">
于 2012-08-07T06:22:59.697 に答える