Displaying Foreign Tags with <xtag>

There may be times when you wish to use an LXP variable value within the contents of an HTML tag. For example, you may have a graphic with a dynamically assigned width. Since LXP only performs variable value substitution within LXP tags, you cannot substitute an LXP variable within an HTML tag as you would with an LXP tag. In other words, the $width variable reference in the following example will not work:

  <!-- WRONG: LXP variable will not be substituted in non-LXP tag -->
  <img src="/images/spacer.gif" width="$width" />

You might think an obvious solution would be to place the LXP <putvar> tag inside of the HTML tag. There is a problem with this approach, however. Specifically, such syntax breaks the integrity of the mark-up of the document. For a mark-up language to be well formed, tags must not be nested within the actual contents of another tag as shown in this example:

  <!-- Not recommended: Tags should not be nested in one another -->
  <img src="/images/spacer.gif" width="<putvar name="width" />">

Note that nesting LXP tags within non-LXP tags can work in some circumstances, though it is not recommended. The LXP well-formedness requirements will probably grow more stringent in the future, and this kind of nesting is an easy way to make your LXP mark-up both lose its readability, as well as its mark-up integrity.

The LXP solution to this problem is the <xtag> element. The <xtag> is used as a wrapper to display any foreign ...

Get Practical PostgreSQL now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.