Is there an equivalent function to string format in XSLT?
I'm working on a multi-lingual site in umbraco. I'm not aware of what languages will be needed, butbeing as they are, one language could order the words differently e.g.
English "Your query 'Duncan' matched 5 results." could translate word for word to "5 results matched 'Duncan' query".
For this reason having a item for "Your query", "matched" and "results" in my umbraco translation isn't feasible. If I was to make this a user control for C# I would have the translator to provide a dictionary item like "Your query '{0}' matched {1} results".
Is there an equivalent function to string format in XSLT?
This is a close analog in XSLT:
The dictionary entry has the following format:
<t>Your query "<query/>" matched <nResults/> results</t>
The transformation (corresponding to 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 wanted, correct result:
Your query "XPath and XSLT" matched 3 results
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With