As of uComponents v6.0.0 all XSLT extensions are automatically registered with Umbraco. Newly created XSLT files (in the back-office) will already contain the appropriate namespaces. For existing XSLT files, you will still need to add the ucomponents.strings
namespace.
Enabling the XSLT extension for use in your XSLT templates.
Add the following XML snippet to your ~/config/xsltExtensions.config
file:
<XsltExtensions>
...
<ext assembly="uComponents.XsltExtensions" type="uComponents.XsltExtensions.Strings" alias="ucomponents.strings" />
...
</XsltExtensions>
Here are available methods in the Strings
library:
Return the first amount of words defined by ‘count’ contained in ‘text’.
Returns: String containing only the first x words.
| Name | Type | Notes |
|——|——|——-|
| text | System.String
| |
| count | System.Int32
| |
| appender | System.String
| (optional - defaults to …
) |
<xsl:value-of select="ucomponents.strings:GetFirstWords($currentPage/bodyText, 30, '...')" disable-output-escaping="yes" />
Converts an email address into a hyperlink.
| Name | Type | Notes |
|——|——|——-|
| email | System.String
| |
| text | System.String
| (optional - defaults to email
) |
<xsl:value-of select="ucomponents.strings:MakeEmailHyperlink('username@domain.com', 'Click here to email me.')" disable-output-escaping="yes" />
Converts all URLs into hyperlinks within a string.
Returns: Returns a string with all URLs turned into hyperlinks.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:MakeUrlHyperlink(umbraco.library:NiceUrl($currentPage/@id))" disable-output-escaping="yes" />
Truncates the middle section of a string, this is ideal for long filepaths or URLs.
Returns: Returns a shortened path of the string.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:PathShortener(umbraco.library:NiceUrl($currentPage/@id))" />
Truncates the inner-string.
Returns: Returns a string with the mid-section truncated.
| Name | Type |
|——|——|
| input | System.String
|
| maxLength | System.Int32
|
<xsl:value-of select="ucomponents.strings:TruncateInner($currentPage/@nodeName, 30)" />
Removes non alpha-numeric characters from a string.
Returns: Returns the string with non alpha-numeric characters removed.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:RemoveChars($currentPage/@nodeName)" />
Reverses the specified input.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:Reverse($currentPage/@nodeName)" />
Makes an alias name safe to use as an XML element name. Removes all spaces and non-alphanumeric characters.
Returns: Returns a safe alias string.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:SafeAlias($currentPage/@nodeName)" />
Spaces out a string on capitals or numbers.
Returns: The string with spaces before each capital letter or number
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:SpaceOutCamelCase(name($currentPage))" />
Strips the <font>
tags from a string.
Returns: Returns the string stripped of all <font>
tags.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:StripFontTags($currentPage/bodyText)" disable-output-escaping="yes" />
Strips the HTML.
Returns: Returns the string stripped of all HTML tags.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:StripHTML($currentPage/bodyText)" />
Strips the whitespace characters from a string.
Returns: Returns the string stripped of any whitespace characters.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:StripWhitespace($currentPage/introText)" />
Strips the non alpha-numeric characters.
Returns: Returns the string with only alpha-numeric characters.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:StripNonAlphaNumeric($currentPage/@nodeName)" />
Strips out all the line-breaks.
Returns: Returns the string with all the line-breaks stripped out.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:StripLineBreaks($currentPage/introText)" />
Changes the case of the string to lowercase.
Returns: Returns the string as lowercase.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:ToLowerCase($currentPage/@nodeName)" />
Changes the case of the string to uppercase.
Returns: Returns the string as uppercase.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:ToUpperCase($currentPage/@nodeName)" />
Changes a string to camelCase.
Returns: The camelCased string
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:ToCamelCase($currentPage/@nodeName)" />
Changes the case of the string to proper case.
Returns: Returns the string in proper case.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:ToProperCase($currentPage/@nodeName)" />
Changes the case of the string to title case.
Returns: Returns the string in title case.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:ToTitleCase($currentPage/@nodeName)" />
Encodes a string as Base64.
Returns: Returns the string encoded as Base64.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:ToBase64String('A string to be converted to Base64.')" />
Decodes a string from Base64.
Returns: Returns the decoded Base64 string.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:FromBase64String('QSBCYXNlNjQgZW5jb2RlZCBzdHJpbmcu')" />
Counts the number of words in a string.
Returns: Returns the number of words in the string.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:WordCount($currentPage/introText)" />
Lowers the case of the HTML tags.
Returns: Returns the string with all HTML tags in lowercase.
| Name | Type |
|——|——|
| input | System.String
|
<xsl:value-of select="ucomponents.strings:LowerCaseTags($currentPage/bodyText)" disable-output-escaping="yes" />
Performs a Coalesce among the supplied arguments. Returns: Returns the first non-null or empty expression among the supplied arguments.
| Name | Type | Notes |
|——|——|——-|
| arg1 | System.String
| |
| arg2 | System.String
| |
| arg3 | System.String
| (optional) |
| arg4 | System.String
| (optional) |
| arg5 | System.String
| (optional) |
<xsl:value-of select="ucomponents.strings:Coalesce(customTitle, introTitle, pageSubtitle, pageTitle, @nodeName)" />
Formats the specified string. Returns: Returns a formatted string.
| Name | Type | Notes |
|——|——|——-|
| format | System.String
| A composite format string (uses .NET syntax). |
| arg1 | System.String
| |
| arg2 | System.String
| (optional) |
| arg3 | System.String
| (optional) |
| arg4 | System.String
| (optional) |
| arg5 | System.String
| (optional) |
<xsl:value-of select="ucomponents.strings:Format('{0} {1} {2} {3:ddMMyy} {4:ddMMyy}', @id, @nodeName, @urlName, @createDate, @updateDate)" />
Concats the specified nodeset.
| Name | Type |
|——|——|
| nodeset | System.Xml.XPath.XPathNodeIterator |
| separator | System.String
|
<xsl:value-of select="ucomponents.strings:Concat($currentPage/widgets/*/nodeId, ',')" />
Removes the duplicate entries from a comma-separated list.
Returns: Returns a comma-separated list with duplicate entries removed.
| Name | Type | Notes |
|——|——|——-|
| list | System.String
| |
| separator | System.String
| (optional - defaults to a comma ,
) |
<xsl:value-of select="ucomponents.strings:RemoveDuplicateEntries('aaa,bbb,ccc,ddd,aaa,ccc,eee', ',')" />
Removes the empty entries from a comma-separated list.
Returns: Returns a comma-separated list with empty entries removed.
| Name | Type | Notes |
|——|——|——-|
| list | System.String
| |
| separator | System.String
| (optional - defaults to a comma ,
) |
<xsl:value-of select="ucomponents.strings:RemoveEmptyEntries('aaa,bbb,ccc,,ddd,,,,,eee', ',')" />
Selects a singular or plural word based on the value of the count.
Returns: Returns the singular or plural word based on the count’s value.
| Name | Type | Notes |
|——|——|——-|
| count | System.Int32
| |
| singular | System.String
| |
| plural | System.String
| |
| prefixCount | System.Boolean | (optional - defaults to false
) |
<xsl:text>You have selected </xsl:text>
<xsl:value-of select="ucomponents.strings:SingularPlural(count($currentPage/widgets/*/nodeId), 'node.', 'nodes.', true())" />
Removes the specified string from the beginning of the target, if it exists.
Returns: Returns the input string with the specified text trimmed from the start.
| Name | Type |
|——|——|
| input | System.String
|
| textToTrim | System.String
|
<xsl:value-of select="ucomponents.strings:TrimStringFromStart($currentPage/@nodeName, 'Some prefix: ')" />
Removes the specified string from the end of the target, if it exists.
Returns: Returns the input string with the specified text trimmed from the end.
| Name | Type |
|——|——|
| input | System.String
|
| textToTrim | System.String
|
<xsl:value-of select="ucomponents.strings:TrimStringFromEnd($currentPage/@nodeName, '! Some suffix')" />