String.Format("您的查询{0}与{1}占位符",theQuery,results.Count)等效于XSLT

Dun*_*can 5 c# xslt

在XSLT中是否有与字符串格式等效的函数?

我正在umbraco的多语言网站上工作.我不知道需要什么语言,但是就像它们一样,一种语言可能会以不同的方式排序,例如

英语"您的查询'Duncan'符合5项结果." 可以逐字逐句翻译成"5匹配'Duncan'查询".

因此,在我的umbraco翻译中有一个"你的查询"项目,"匹配"和"结果"是不可行的.如果我要让它成为C#的用户控件,我会让翻译者提供一个字典项,例如"你的查询'{0}'匹配{1}结果".

Dim*_*hev 5

在XSLT中是否有与字符串格式等效的函数?

这是XSLT中的一个近似模拟:

字典条目具有以下格式:

<t>Your query "<query/>" matched <nResults/> results</t>
Run Code Online (Sandbox Code Playgroud)

转换(对应string.format())非常简单:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>

  <xsl:param name="pQuery" select="'XPath and XSLT'"/>
  <xsl:param name="pNumResults" select="3"/>

 <xsl:template match="query">
  <xsl:value-of select="$pQuery"/>
 </xsl:template>

 <xsl:template match="nResults">
  <xsl:value-of select="$pNumResults"/>
 </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

它产生了想要的,正确的结果:

Your query "XPath and XSLT" matched 3 results
Run Code Online (Sandbox Code Playgroud)