【发布时间】:2013-02-05 01:35:31
【问题描述】:
我有一个名为 $SearchRecipe 的参数,它包含一个字符串,我总是将小写字符串传递给它。
我有一个 XML 文件,我正在使用我的 xslt 和 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 有着绝对的夜生活。此外,当我写这个寻求帮助的请求时,我已经做了几个小时的工作,最后一个小时我花了各种各样的方法来解决这个小写问题。因此,如果我没有正确询问,我想提前道歉。
如果你想看大图,我已经在这里上传了我的代码:
【问题讨论】:
-
快速旁注:我进入了这个 stackoverflow 页面:stackoverflow.com/questions/3053828/… 但是我仍然无法将其应用于我的代码并使其正常工作。