0

常に小文字の文字列を渡す文字列を保持する$SearchRecipeという名前のパラメータがあります。

xsltを使用してアクセスしているXMLファイルと、xmlファイルのデータの例があります。

<ARecipe>
    <RecipeNo>117</RecipeNo>
    <ItemName>Veggie Sausages with Beans and Chips</ItemName>
    <RecipeInfo>
        <Ingredients>Linda Mcartney Sausages(2 per serving), Beans (400g per serving), Chips(Handful), Random Chillis (up to you how much)</Ingredients>
        <Instructions>Put on fat fryer, insert chips and sausages. Put on wok, insert beans and add some random chillis etc. Heat beans and remove cooked Sausages and Chips. Place sausages and chips in tissue to remove excess oil. Place in a plate and serve warm.</Instructions>
        <RecipeType>Main</RecipeType>
        <Vegetarian>No</Vegetarian>
    </RecipeInfo>
</ARecipe>

すべてのItemNameノードを調べて、正常に機能する文字列と比較するクエリを実行しています。たとえば、文字列にVを入れると、これは(ARecipe)のItemNameと一致し、これがxslt出力に表示されます。ただし、vを値として渡すと、この特定のノード(ARecipe)は表示されません。

私はこれらの行を使用してxmlファイルを調べています:

<xsl:variable name="matchedRecipes"
     select="ARecipe[
           ($SearchType = 'Start' and starts-with($Test, $SearchRecipe)) or
           ($SearchType = 'Contains' and contains(ItemName, $SearchRecipe)) or
           ($SearchType = 'RecipeType' and 
                        contains(RecipeInfo/RecipeType, $SearchRecipe))
                      ]" />

  <xsl:if test="$SearchType = 'Start' or $SearchType = 'Contains'">
    <xsl:apply-templates select="$matchedRecipes">

私がこれまでに試したことはこれです:

        <xsl:variable name="Test">
    <xsl:value-of select="translate('ARecipe/ItemName',$ucletters,$lcletters)"/>
    </xsl:variable>

私はほとんどの言語などの初心者ですが、C#でこの種のことをかなり簡単に行うことができます。私は、xsltで絶対的なナイトメイトを持っています。また、私がこの助けを求めるリクエストを書いたとき、私はすでに数時間この作業を行っていました。最後の1時間は、この小文字の問題を解決するためにあらゆる種類の試みに費やしました。ですので、きちんとお伺いしていませんので、あらかじめお詫び申し上げます。

より大きな画像を見たい場合は、ここにコードをアップロードしました:

http://pastebin.com/w8AsiQRg

4

1 に答える 1

1

次のようなことをする必要があります。

<xsl:variable name="SearchLc" select="translate($SearchRecipe, $ucletters, $lcletters)" />
<xsl:variable name="matchedRecipes"
     select="ARecipe[
           ($SearchType = 'Start' and 
              starts-with(translate(ItemName, $ucletters, $lcletters), $SearchLc)) or
           ($SearchType = 'Contains' and 
               contains(translate(ItemName, $ucletters, $lcletters), $SearchLc)) or
           ($SearchType = 'RecipeType' and 
                    contains(translate(RecipeInfo/RecipeType, $ucletters, $lcletters),
                                 $SearchRecipe))
                      ]" />

事前に小文字バージョンの検索テキストを取得できますが、選択XPath内の個々の項目の小文字を使用する必要があります。

于 2013-02-05T03:20:49.837 に答える