Splitting a string and substring conundrum
This is an open discussion with 5 replies, filed under XSLT.
Search
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:
- either write a custom text formatter
- or have a look at how Nick's Twita@talinkahashifyer works.
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(.,' ')"/></span> <span class="title"><xsl:value-of select="substring-after(.,' ')"/></span>
Create an account or sign in to comment.
I'm trying but failing to think how I could transform this sample text:
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:
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.