Search

Hello all, I downloaded, installed and have been playing enthusiastically with Symphony since yesterday. I am a complete virgin when it comes to XSLT, but I know it is what I need in order to keep my content nicely separated from markup, and nimble enough to write once, publish everywhere.

So, hi — how are you? I am a UX designer with big interest in content strategy, and Symphony is going to be the tool I need in my life to make my content awesome online. But, I have a question, as you know from the topic heading.

I have been playing around with XSLT today in Symphony CMS and I can see very clearly how HTML is output from XML using the transforms. That is great. What I can’t wrap my head around is how, if you have acronyms defined in their own section of XML, they can then be inlined when output for HTML? Lets say we have a content summary for a topic. The summary copy will be extracted from an XML node, and transformed via XSLT into HTML by spitting it out of the node. For web accessibility and good markup purposes, I need to wrap an abbreviation like the following example:

<abbr title="World Wildlife Fund">WWF</abbr>

which will likely occur mid sentence in the content that is being spat out. Is it possible with regular expressions, or otherwise, to target certain strings of text and apply the correct abbreviations, acronyms and other inline HTML elements to these strings?

Say hello to the Ninja Technique my friend, coupled with some XPath string functions. There may also be a benefit to using EXSLT's replace() here too

Thanks Lewis, this looks like it will be able to provide what I am looking for, but the article does make some assumptions that the reader will know how to piece these components together. I have an XML document called terminology.xml, residing in /workspace/library/ which looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<terminology>
    <abbreviations>
        <term abbr="Extensible Markup Language">XML</term>
    </abbreviations>
</terminology>

I guess that I need to reference this XML in my XSLT, so I have the following:

<xsl:include href="{$workspace}/library/terminology.xml"/>

I took the article pretty much verbatim, to try it out, when it came to writing the XSL Template:

<xsl:template match="terminology//*">
    <xsl:element name="{name()}">
        <xsl:apply-templates select="* | @* | text()"/>
    </xsl:element>
</xsl:template>

Now, how do I wire the XML up with the template? Also, the article didn’t really answer how I can output copy (which in my case, will be from a different XML doc than the terminology.xml I have referenced here) and then find, for example WWF in that text, and on each occasion wrap it with an abbreviation tag containing a title attribute which pulls in text from the corresponding terminology.xml node.

Any pointers?

Hi digikev,

Firstly welcome to the community :)

Regarding your issue, you mentioned you have a terminology lookup file (terminology.xml). Can you also describe how your body XML look like? For example, would your body text be wrapped in an XML element of some kind:

<body>
    <p>This is some text.</p>
    <p>Here's a <term>keyword</term>.</p>
</body>

If your body text is also in a format that XML can parse (as opposed to being all clumped in straight text), then using the HTML ninja technique is quite straight forward. Notice the <term> element. The XSLT could match these elements and do a look-up from the <terminology> element.

If the terms in your body text do not include wrapping elements (straight text), then it would be better to look at using EXSLT's replace() function that Lewis mentioned. However, this is a pretty deep rabbit hole to jump into.

Unfortunately, you've managed to pick the most complex thing to wrap your head around for your first foray into XSLT!

Any case, I'll try my best to help you out.

Hi Allen, thank you for the warm welcome. Due to my hosting provider disabling loopback requests, this was put on hold for a couple of days. However, I am now back up and running (kinda…).

This thread was running a little slow, so I also posed the question on Stackoverflow and have a reply back from Ravish, with a good chunk of code, which seems logical for handling this. Do you think this will do the trick? And if so, any pointers on debugging this code would be really appreciated.

Granted, I am jumping in very deep here. I have turned to Symphony to handle this exact kind of problem though whilst maintaining semantically great content. This proof of concept will have me flying :)

Okay, it has been a bit of trial and error and some fantastic guidance from someone on Stackoverflow, but I now have a working example of a central XML repository for abbreviations.

I will now be able to use this for more granular HTML use cases.

I've only just been able to come back to this thread. Looks like it's been solved. You'd be glad to know that XSLT doesn't get any more complicated than this. The stuff you've implemented covers a very wide spectrum of XSLT concepts.

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