I’m rather new to XSL Stylesheets, so bear with me here.
I’ve got an embedded C# block in my .xsl. It’s there because I need something that will take a string of numbers (Ex: “1,3,5”). I want it to the numbers on the ‘,’. The code block is part of an XSL loop, so it passes in which iteration it’s on and compares that number to the list that came in via the string. If the iteration-count is in the list, return true. If it’s not, return False. The string can also come in as “all”, in which case just return true.
This is what I came up with:
<msxsl:script language="c#" implements-prefix="user">
<![CDATA[
public bool showStoryImg(string desiredImgs, int currentNum){
bool rtnVal = false;
try
{
if (desiredImgs == "all")
{
rtnVal = true;
}
else
{
string[] numStrArr = desiredImgs.Split(',');
int[] values = new int[numStrArr.Length];
for(int x = 0; x < numStrArr.Length; x++)
{
values[x] = Convert.ToInt32(numStrArr[x].ToString());
}
foreach(int y in values)
{
if(currentNum == y){
return true;
}
else
{
rtnVal = false;
}
}
}
}
catch(Exception e)
{
rtnVal = false;
}
return rtnVal;
}
]]>
</msxsl:script>
However I fear my problem is that XSL has no way of using .NET Libraries, hence why this code doesn’t work. Are there any suggestions as to how I should go about this?
No extension function is needed at all!
This transformation:
when applied on the following XML document (none provided in the question!):
processes only the elements with position that is specified in the
$pImagesparameter — in this case just outputs theirsrcattributes: