当前位置: 动力学知识库 > 问答 > 编程问答 >

vb.net - Custom xsl function with parameter array

问题描述:

I want to create a function for XSL to resolve a text like "Inserted by {0} at {1}" in "Inserted by Admin at 2013-05-13T10:02:17". I use XSL 1.0 and define my own functions in .NET. I try this like

Public Class MyStringExtension

Public Function Format(ByVal value As String, ByVal ParamArray args As String()) As String

Return String.Format(value, args)

End Function

End Class

<xsl:value-of select="MyStringExtensionNamespace:Format('Inserted by {0} at {1}', 'Admin', '2013-05-13T10:02:17')" />

It seems that the ParamArray option not works or perhaps is not allowed in this case. With any other function I have no problems. Is there a way to define a function which allows multiple parameters without defining for each possible one function. (something like concat('Param 1', ' Param 2', 'Param 3', 'Param 4', 'Param 5', ...))

网友答案:

You can do this within XSL:

<func:function name = "formatMyString">
  <xsl:param name="firstParam" />
  <xsl:param name="secondParam" />
  <func:result select="concat('Inserted by ', $firstParam,' at ', $secondparam)"/>
</func:function>
分享给朋友:
您可能感兴趣的文章:
随机阅读: