Search

I'm trying but failing to think how I could transform this sample text:

Jonnh Wind
Managing Director

Allan Partidge
Financial Cnotroller :)

Russ Abbot
Joke Engineer

This is just plain text in a text area.. no markdown or WYSIWYG editors.. don't want them breaking the beautifully crafted front end now do we!

What I am trying to achieve is this:

<ul>
<li>Jonnh Wind<span>Managing Director</span></li>
<li>Allan Partidge<span>Financial Cnotroller</span></li>
<li>Russ Abbot<span>Joke Engineer</span></li>
</ul>    

I was thinking of using the Split string utility and look for the presence of two new line characters.. I have this working.. but how do I then do a recursive split string on the li to get the <span> to appear after the carriage return?

My mind is like mush today.

no markdown or WYSIWYG editors.. don't want them breaking the beautifully crafted front end now do we!

Why don't you just apply Markdown without telling your editors? This way you'd get markup you could transform using the ninja technique. Unwanted markup your editors created can be removed easily using <xsl:value-of />.

If you'd like to stick to your plain string:

Hi Nils.. I was actually looking at a post you submittwd about counting characters and splitting for ahead start. but Nicks utility sounds like a good starting point as well.

I am using Multilingual field and thought a list with an extra line after each item would produce an extra paragraph tag as described in the official markdown basic tutorial.. but nothing was output.. I'll keep lokkjng into it.

@moonoo2, that's pretty easy to do I just use it all the time.

I use the XSLT ninja technique when I have text in that format; and I would treat each line separately.

I would usually do something of the sort <xsl:value-of select='/data/datasource/entry/p[1]'/> for example; which takes out the first paragraph attribute then you can do with it whatever you'd like. I'd still use a basic markdown formatter however. So the texts would be split into paragraphs nicely allowing you to format each separately.

If you don't know how many pairs you'll have you can always split it up in a template that matches in pairs and loop over them to create the right template.

So if I did a template match for the containing p tags I could use substring-before the carriage return to style the name and substring-after the carriage to style their job title right?

Got it! thanks for the tip Jon/Nils:

<xsl:apply-templates select="entry/principals/p"/>

<xsl:template match="entry/principals/p" >
        <span class="name"><xsl:value-of select="substring-before(.,'&#10;')"/></span>
        <span class="title"><xsl:value-of select="substring-after(.,'&#10;')"/></span>

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