String.Format ("Your query {0} with {1} Placeholders", theQuery, results.Count) Equivalent in XSLT

Is there an equivalent function for string format in XSLT?

I am working on a multilingual website at umbraco. I don’t know which languages ​​are needed, but since they exist, one language can arrange words in a different way, for example.

English "Your query" Duncan "matched 5 results." can translate word for word in "5 results match the query" Duncan ".

For this reason, the presence of the element "Your request", "match" and "results" in my umbraco translation is not possible. If I were to make this a custom control for C #, I would provide the translator with a dictionary element such as "Your query" {0} "matching results {1}".

+5
source share
2 answers

Is there an equivalent function for string format in XSLT?

This is a close equivalent in XSLT :

The dictionary entry has the following format:

<t>Your query "<query/>" matched <nResults/> results</t>

Converting (appropriate string.format()) is very simple:

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

, and it produces the desired, correct result :

Your query "XPath and XSLT" matched 3 results
+5
source

All Articles