0

I have a param named $SearchRecipe which holds a string that i'm always passing a lowercase string to.

I have an XML file which i'm accessing using my xslt and example of some data from the xml file :

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

I'm running a query to go through all the ItemName nodes and compare it to my string which works fine. For example if I put V in the string it matches the ItemName in this (ARecipe) and this gets displayed in my xslt output. However if I pass v as a value then it won't bring this particular node (ARecipe).

I'm using these lines to go through the xml file :

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

What I have tried so far is this :

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

I'm a novice in most languages etc, but I would be able to do this kind of thing in C# fairly easily, i'm having an absolute nightmate with xslt. Also when I wrote this request for help, I had already been doing this work for a few hours and the last hour I've spent trying all sorts to get this lowercase issue to resolve. So if I've not asked properly, I would like to appologize in advance.

If you would like to see the larger picture I have uploaded my code here :

http://pastebin.com/w8AsiQRg

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
JARRRRG
  • 917
  • 2
  • 14
  • 44
  • Quick side note : I went on this stackoverflow page : http://stackoverflow.com/questions/3053828/lowercase-conversion-in-xsl?rq=1 however I could still not apply that to my code and get it to work. – JARRRRG Feb 05 '13 at 01:39

1 Answers1

1

You'll need to do something like this:

<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))
                      ]" />

You can get the lowercase version of the search text ahead of time, but then you'll need to do the lower-casing of the individual items inside the selection XPath.

JLRishe
  • 99,490
  • 19
  • 131
  • 169
  • I see now, that works great. I was getting the variable syntax correct as I did the test by setting it a default value and i'm guessing the syntax to convert it from uppercase to lowercase was also correct, I was missing the part where I convert the ItemName to lowercase aswell. Cheers @JLRishe – JARRRRG Feb 05 '13 at 09:17