Search

Hi, Some entries starts with string and next opening bracket e.g. Test (test)

OUTPUT:

Test
(test)

and some starts only with opening bracket e.g. (test)

OUTPUT:

(test)

My question is: How to make condition like this:

  • when starts with string insert <br /> tag before opening bracket or after this string
  • when starts with opening bracket do not insert <br /> tag

Code:

<xsl:choose>
  <xsl:when test="starts-with('{$p}', '(')">
    <xsl:value-of select="p"/>
  </xsl:when>
  <xsl:when test="starts-with('', '')">

  </xsl:when>
  <xsl:otherwise>
    <p>error</p>
  </xsl:otherwise>
</xsl:choose>  

See this utility for string replacement.

<xsl:choose>

    <!-- Starts with '(' or doesn't contain '(', display normal -->
    <xsl:when test="starts-with(., '(') or not(contains(., '('))">
        <xsl:value-of select="."/>
    </xsl:when>

    <!-- Other text, replace with what you need -->
    <xsl:otherwise>
        <xsl:value-of select="string:replace(., '(', '&lt;br/>(')" disable-output-escaping="yes"/>
    </xsl:otherwise>

</xsl:choose>

This line outputs

<xsl:value-of select="string:replace(., '(', '&lt;br/>(')" disable-output-escaping="yes"/>

some errors:

xmlXPathCompOpEval: function replace bound to undefined prefix string
xmlXPathCompiledEval: 2 objects left on the stack.
XPath evaluation returned no result.
runtime error: file /.../master.xsl line x element value-of

edit:

starts-with( {$p} , '(')

how to put in the first parameter text input from XML?

string:replace is an exsl function. Vlad forgot to mention that...

Parameter use in xpath functions don't need the curly braces:

starts-with($p, '(')

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details