14.3.1.VSP Markup & Basic Functions

All VSP specific markup is represented as a processing instruction (<? ... ?>).

  statement ;
  statement ;

This markup introduces Virtuoso PL code to a VSP page, which otherwise may normally contain HTML markup. The code enclosed must begin and end at a statement boundary but a compound statement may begin in one <?vsp tag and end in another. Code outside of these blocks is ignored by Virtuoso and placed directly on the HTTP stream to be sent to the client.

[Tip] See Also:

The SQL Procedure Language Guide chapter.

Several functions exist to allow VSP code to send data to the HTTP stream. They are basically the same but offer different escaping mechanisms to suit different purposes:

http (in value varchar, in stream any);

http_value ( in value any, in tag varchar, in tag varchar, in stream any);

http_url ( in value any, in tag varchar, in stream any);

These functions output their value argument to the specified stream with varying escaping. The value argument may be any scalar object, i.e. string, date or number and will automatically be cast to varchar before further processing.

http() will print out the contents of value cast to string without any modification.

http_value() will use HTML escapes such that '< ' will be output as '&lt; '.

The http_url() function will use URL escapes such that '+' replaces spaces and hex escapes like %25 will replace '%'. If http_value() gets an XML entity returned by a path expression it outputs the serialization of the entity, including children. This is not the string value since this has the entity start and end tags and other markup. The tag argument allows specifying a tag in which the value is to be enclosed. A non-string value, e.g. 0 or null will cause no tag to be put around the value.

The stream argument may be omitted, in which case it defaults to the HTTP client of the calling procedure. If present, a value of integer 0 will mean the http client. If non-0 the value must be an object returned by string_output() .

These HTTP functions are commonly combined with sprintf() which allows string composition based on a template. When using sprintf() to compose data to send to the user agent the %V and %U letters can be used to introduce escapes similar to http_value and http_url, respectively.

Example14.6.HTTP Functions

http (' % <b>')          ' % <b>'
http_value (' % <b>')    ' % &lt;b&gt;'
http_url (' % <b>')      '+%25+<b>'
http_value (12, 'li')    '<li>12</li>'

Markup Short-hands

VSP markup short-hands exist for the http_value() and http_url() functions to perform the same task outside of a VSP code block. This can improve readability of VSP pages.

<?= expression ?>  equiv.  http_value()
<?/ expression ?>  equiv.  http_url()

These markups are shorthand for substituting values of expressions into the output. The <?= tag accepts a SQL expression and casts the value into a string, which is sent to the output. The <?/ markup sends the value of the expression to the client with HTTP URL escapes.

Example14.7.VSP Markup

Here is a very simple example of making a two column HTML table from the results of a "select" SQL statement. First using normal functions:

<h2>List of Users</h2>
  for (select u_name, u_password from sys_users ) do {
    http (u_name);
    http (u_password);

This fragment outputs a table of user names and passwords. We have chosen to not end the code block until the end of the result so we have repeatedly used the http() function to output parts of the table also.

Now the same code but including shorthands:

<h2>List of Users</h2>
<?vsp for (select u_name, u_password from sys_users ) do { ?>
    <td><?=u_name ?></td>
    <td><?=u_password ?></td></tr>
      <?vsp } ?>