Dynamic Text Variables for Elements and Attributes

You can use dynamic text variables to insert the value of an element or an attribute from your content into a topic. For example, you could add the value of the edition element from a publication into the text in a topic.

To reference elements and attributes, you will need:

  • A basic understanding of XPath 1.0. XPath is required for navigating the elements in the XML output.

  • Access to the XML file that contains all of your content (see Plan your References with the Debug XML File). You can use this file to plan your XPath references. Once you know which elements and attributes are needed, you can insert the appropriate references in your dynamic text variables.

  • To insert dynamic text variables in your topics, and add the references using the appropriate syntax.

To learn about XPath 1.0, see https://www.w3schools.com/xml/xpath_intro.asp.

Plan your References with the Debug XML File

Paligo can provide you with a single XML file that contains all of the content in a publication (the publication itself and all of the topics). You can use this XML file to get a better understanding of the structure of your content, so that you plan the XPath expressions for your dynamic text variables. Use XPath 1.0 expressions to access the elements and attributes in your content.

To find out how to get the XML file, watch the video or read the following instructions:

  1. In the Content Manager, find your publication, select its option ( ... ) button, and then select Publish.

  2. On the Publish document dialog, choose the type of output you want, set the Languages, Profiling Attributes, and regular Variables, and then select the Make debug build option.

    The Make debug build option tells Paligo to include the build files in the output as well as the actual output. One of the build files is an XML file that contains your content.

    Publish document settings. Make debug build is enabled.
  3. Select Publish document to publish your content.

    When it downloads, unzip it and look for the XML file that contains your content.

    For PDF outputs, the XML file has the same name as the publication and has a language suffix. For example, "Acme_100_user_guide-en.xml".

    For HTML, HTML5, XML, Word, and SCORM outputs, the XML file is named index and has a language suffix, for example, index-en.xml.

  4. Open the XML file from step 3 and use it to plan your XPath 1.0 expressions. When you have planned the expressions, you can insert dynamic text variables into your content and add the relevant expressions.

Insert a Dynamic Text Variable

When you know what elements and attributes you want to use for your dynamic text variables, you can start adding them to your topics.

To insert a dynamic text variable:

  1. Find the topic that is going to contain the dynamic text variable and open it in the editor.

  2. Position the cursor at a valid position for the dynamic text variable. This can be any position where a phrase element is valid can be added, for example, inside a para element.

  3. Use the element context menu to add a phrase element.

    To access the element context menu, press Alt and Enter (Windows) or Option ⌥ and Enter (Mac).

  4. Select the phrase element and then in the Element attributes panel, add the role attribute. Set its value to:

    dyntextvar

    phrase-role-dyntextvar.jpg

    This will add the minimum required syntax for the dynamic variable:

    <phrase role="dyntextvar">${}$</phrase>
  5. When you have added the dynamic text variable, enter the relevant XPath expression to access the element or attribute you want to use.

Note

If you use an expression to access an element or attribute that does not exist, the dynamic text variable will be empty (blank) in the output.

When you are writing XPath expressions, there are several things you need to be aware of:

  • Include the "d:" prefix for navigating the XML, for example:

    ${/*[1]/d:info/d:title}$

    The namespace prefix d is bound to http://docbook.org/ns/docbook

  • There are DocBook attributes that do not require a prefix and there are also some custom Paligo attributes, known as extension attributes. To access the extension attributes, use the @xinfo prefix, for example:

    ${@xinfo:time-modified}$

    The namespace prefix xinfo is bound to http://ns.expertinfo.se/cms/xmlns/1.0.

  • For PDF outputs, the top-level node that you can access is article. You cannot access the article's parent node (part).