$vof() Function

Top  Previous  Next

$vof() function can be used within the values of properties to achieve dynamic data from XML. It is transformed by the Application Studio into appropriate XSL codes depending on where it is used.

Example:

XML Data:

 

 <?xml version="1.0" encoding="UTF-8"?>

 <root>

  <Employee>

    <Name>John Watson</Name>

  </Employee>

 </root>

 

 

Usage on Page in the value property of a text element:

Name: $vof(/Employee/Name)

The Application Studio will compile this definition into the following:

<td>Name: <xsl:value-of select="/root/Employee/Name"/></td>

 

And the result on the browser will be

Name: John Watson

 

Note: We don't have to give the root node since the Application Studio will always include it.

The $vof() function can be used in two syntaxes.

Syntax 1

$vof(expression [; default-expression ])

 

First the expression is evaluated. If the result is a value other than the blank then it is used; otherwise the result of the default-expression is used.

Syntax 2

$vof(test-expression ; then-expression [; else-expression])

or

$vof(test-expression ; then-expression [; test-expression ; then-expression [; else-expression])

 

Examples:

Expression

$vof(name)
 

Will be transformed into

 

<xsl:value-of select="name"/>

 

 

Expression

$vof(name;'No name given')
 

Will be transformed into

 

  <xsl:choose>

    <xsl:when test="name != ''"><xsl:value-of select="name"/></xsl:when>

    <xsl:otherwise><xsl:value-of select="'No name given'"/></xsl:otherwise>

  </xsl:choose>

 

 

Expression

$vof(count > 5 ? 'Greater than 5' ; 'Less or equal to 5')
 

Will be transformed into

 

  <xsl:choose>

    <xsl:when test="count > 5"><xsl:value-of select="'Greater than 5'"/></xsl:when>

    <xsl:otherwise><xsl:value-of select="'Less or equal to 5'"/></xsl:otherwise>

  </xsl:choose>

 

 

Expression

$vof(Age < 15 ? 'Kid' ; Age < 30 ? 'Youth' ; Age < 50 ? 'Middle Aged' ; 'Pensioner')
 

Will be transformed into

 

  <xsl:choose>

    <xsl:when test="Age &lt; 15"><xsl:value-of select="'Kid'"/></xsl:when>

    <xsl:when test="Age &lt; 30"><xsl:value-of select="'Youth'"/></xsl:when>

    <xsl:when test="Age &lt; 50"><xsl:value-of select="'Middle Aged'"/></xsl:when>

    <xsl:otherwise><xsl:value-of select="'Pensioner'"/></xsl:otherwise>

  </xsl:choose>

 

The Nested Usage

The nested usage of the function can be made by enclosing the expressions with  parentheses.

Example:

$vof(A = B ? ( C ; 'X') ; (C = D ? X ; Y))
 

Will be transformed into

 

  <xsl:choose>

    <xsl:when test="A = B">

      <xsl:choose>

        <xsl:when test="C != ''"><xsl:value-of select="C"/></xsl:when>

        <xsl:otherwise><xsl:value-of select="'X'"/></xsl:otherwise>

      </xsl:choose>

    </xsl:when>

    <xsl:otherwise>

      <xsl:choose>

        <xsl:when test="C = D"><xsl:value-of select="X"/></xsl:when>

        <xsl:otherwise><xsl:value-of select="Y"/></xsl:otherwise>

      </xsl:choose>

    </xsl:otherwise>

  </xsl:choose>