SPFE Documentation | Collections > SPFE Function Reference > process-placeholders
Function: process-placeholders
process-placeholders(string as item()*, literal-name as item()*, placeholder-name as item()*) as node()*
- Description
-
Processes a string to determine if it contains placeholder markup in the form of a string contained between "{" and "}". Recognizes "{{}" as an escape sequence for a literal "{". Nesting of placeholders is not supported. The use of a literal "{" or "}" inside the placeholder string is not supported. The function does not attempt to detect or report these conditions, however. $string is the string to process. $literal-name is the element name to wrap around a the literal parts of $string. $placeholder-name is the element name to wrap around the placeholder parts of $string.
- Return value
-
Return type: node()*
Returns an XML sequence in which the literal portions of the input string are wrapped in an element whose name is passed as the literal-name parameter and the placeholder portions of the string are wrapped in an element whose name is passed as the placeholder-nameparameter.
For example, given the following call:
sf:process-placeholders('foo{bar}bas','lit','var')
The return value would be an XML sequence like this:
<lit>foo</lit><var>bar</var><lit>bas</lit>
- Source file
-
$SPFEOT_HOME/1.0/scripts/common/utility-functions.xsl
Parameters
- string
-
Type: item()*
The string to be processed.
- literal-name
-
Type: item()*
The name of the XML element to use to wrap the literal portions of the string.
- placeholder-name
-
Type: item()*
The name of the XML element to use to wrap the placeholder portions of the string.
Definition
<xsl:function name="sf:process-placeholders" as="node()*"> <xsl:param name="string"/> <xsl:param name="literal-name"/> <xsl:param name="placeholder-name"/> <xsl:analyze-string select="$string" regex="\{{([^}}]*)\}}"> <xsl:matching-substring > <xsl:choose > <xsl:when test="regex-group(1)=''"/> <xsl:when test="regex-group(1)='{'"> <xsl:choose > <xsl:when test="$literal-name ne ''"> <xsl:element name="pe:{$literal-name}"> <xsl:value-of select="regex-group(1)"/> </xsl:element> </xsl:when> <xsl:otherwise > <xsl:value-of select="regex-group(1)"/> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise > <xsl:element name="pe:{$placeholder-name}"> <xsl:value-of select="regex-group(1)"/> </xsl:element> </xsl:otherwise> </xsl:choose> </xsl:matching-substring> <xsl:non-matching-substring > <xsl:if test="not(normalize-space(.)='')"> <xsl:choose > <xsl:when test="$literal-name ne''"> <xsl:element name="pe:{$literal-name}"> <xsl:value-of select="."/> </xsl:element> </xsl:when> <xsl:otherwise > <xsl:value-of select="."/> </xsl:otherwise> </xsl:choose> </xsl:if> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:function>