Using CSS instead of XPath in Xopus config to set placeholder text in Xopus

We have URLs that are generated from the main topic’s title element and we wanted the authors to be aware of this when they created a page in Xopus. I thought it would be a simple update to the Xopus config.xml file but it turned out not to be. In the end, we added content using CSS instead of using the Xopus config like this:

/* This adds text to Xopus specifically on the first page title*/
#xopus-xsl-root div h1.topic-title:first-of-type .xopus-placeholder:after {
  content: ' (used for generating page URL)';
}

I believe this could do with a little more refinement but it’s worked in all the cases we’ve tested so we are happy.

If you are interested in what didn’t work, keep reading.

One of the limitations of the Xopus placeholder configuration option is that it is not really XPath so it only matches on the element name, attribute name or a class name.  This is documented on the Xopus Use of XPath in configuration FAQ page.

So we first tried:

<x:node match="class('topic/title')" preferElementsOnlyParent="true">
  <x:name xml:lang="en">Title (used to generate URL)</x:name>
  <x:placeholder xml:lang="en">{name}</x:placeholder>
</x:node>

But this added the message ‘ (used to generate URL)’ to the titles on figures, sections and other elements. My next thought was to do add the longer placeholder only to actual descendants of the topic element (and go back and add concept, etc. later) like this:

<x:node match="topic/title" preferElementsOnlyParent="true">
  <x:name xml:lang="en">Title (used to generate URL)</x:name>
  <x:placeholder xml:lang="en">{name}</x:placeholder>
</x:node>
<x:node match="class('topic/title')" preferElementsOnlyParent="true">
  <x:name xml:lang="en">Title</x:name>
  <x:placeholder xml:lang="en">{name}</x:placeholder>
</x:node>

This resulted in not showing the additional text message anywhere because the Xopus config doesn’t use full XPath, as I mentioned earlier so a match of topic/title matches all titles and since class(‘topic/title’) also matches the element and it comes later in the file, that is the version that was used.