CallXML 3.0 Development Guide Home  |  Frameset Home

  XPath Expressions: Part 2  |  TOC  |  I: CallXML Grammar Guide  

Xpath Functions

Xpath 1.0 has a set of built-in functions that allows us developers a means of further manipulating our data returned from an XML query. While the current Voxeo implementation does not support the full library of functions, we do support most of them, and have even added a few extensions of our own to allow even more flexibility. The list of supported functions is as follows:


Nodeset Functions


Boolean Functions


String Functions


Number Functions


Other Functions


Our examples below illustrate the usage of the various functions within the CallXML3.0 context. Remember, as this example is based on <log> statements, you will not hear anything when you map this application and call it. Instead, you should open the voxeo debugger in order to truly see this code in action.


NodesetFunctions.xml


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

<callxml version="3.0">

<!-- fetch our XML document, and assign it to a locally scoped CallXML variable -->
<fetch value="ConjunctionJunction.xml" var="myFetch" type="xml"/>

  <block label="NodeSetFunctions" value="$myFetch;">

<!-- COUNT -->
  <assign var="nodeCount" expr="count(/var/myFetch/numbers/digit/text())"/>
  <log>*** NODECOUNT FUNCTION: $nodeCount; ***</log>
    <wait value="1s"/>

<!-- LAST -->
  <assign var="nodeLast" expr="/var/myFetch/numbers/digit[last()]/text()"/>
  <log>*** NODELAST FUNCTION: $nodeLast; ***</log>
    <wait value="1s"/>

<!-- LIST -->
  <assign var="listFunction" expr="list(//strings/str1/text())"/>
  <log>***  LIST FUNCTION : $listFunction; ***</log>

<!-- LIST RANGE -->
  <assign var="listRangeFunction" expr="list-range(5)"/>
  <log>***  LIST RANGE FUNCTION : $listRangeFunction; ***</log>
    <wait value="1s"/>

<!-- LIST TEXT -->
  <assign var="listTextFunction" expr="list-text(//strings/str1/text())"/>
  <log>***  LIST TEXT FUNCTION : $listTextFunction; ***</log>
    <wait value="1s"/>


<!-- LIST XML -->
  <assign var="listXMLFunction" expr="list-xml(//strings/str1/text())"/>
  <log>***  LIST XML FUNCTION : $listXMLFunction; ***</log>
    <wait value="1s"/>


<!-- NAME -->
  <assign var="nameFunction" expr="name(//strings/child::*)"/>
  <assign var="nameFunction2" expr="name(//strings/str2)"/>
  <log>*** NAME FUNCTION : $nameFunction; ***</log>
  <log>*** NAME FUNCTION2 : $nameFunction2; ***</log>
    <wait value="1s"/>

  </block>

</callxml>


BooleanFunctions.xml


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

<callxml version="3.0">

<!-- fetch our XML document, and assign it to a locally scoped CallXML variable -->
<fetch value="ConjunctionJunction.xml" var="myFetch" type="xml"/>


  <block label="BooleanFunctions" value="$myFetch;">

<!-- BOOLEAN -->
  <log>*** BOOLEAN 1***</log>
  <log expr="boolean('')"/>
    <wait value="1s"/>

  <log>*** BOOLEAN 2 ***</log>
  <log expr="boolean('false')"/>
    <wait value="1s"/>

<!-- NOT -->
  <assign var="notFunction" expr="not(//booleans/bool[1]/text())"/>
  <log>***  NOT FUNCTION1 : $notFunction; ***</log>
    <wait value="1s"/>

  <assign var="notFunction" expr="not(//booleans/bool[2]/text())"/>
  <log>***  NOT FUNCTION2 : $notFunction; ***</log>

  <assign var="notFunction" expr="not(false())"/>
  <log>***  NOT FUNCTION3 : $notFunction; ***</log>

  </block>

</callxml>


StringFunctions.xml


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

<callxml version="3.0">

<!-- fetch our XML document, and assign it to a locally scoped CallXML variable -->
<fetch value="ConjunctionJunction.xml" var="myFetch" type="xml"/>



  <block label="StringFunctions">

<!-- CONCAT -->
  <log>*** CONCAT FUNCTION: ***</log>
  <log expr="concat('test', 'passes')"/>
  <wait value="1s"/>

<!-- CONTAINS -->
  <log>*** CONTAINS FUNCTION contains: ***</log>
  <log expr="contains('foobar', 'foo')"/>
  <wait value="1s"/>

<!-- NORMALIZE SPACE -->
  <assign var="normalizeFunction" expr="normalize-space(//strings/str2[2]/text())"/>
  <log>*** NORMALIZE FUNCTION: $normalizeFunction; ***</log>


  <assign var="normalizeFunction" expr="normalize-space('  SETH    BULLOCK    ')"/>
  <log>*** NORMALIZE FUNCTION - STATIC STRING: $normalizeFunction; ***</log>
  <wait value="1s"/>

<!-- REGEXPR REPLACE -->
  <assign var="regExFunction" expr="regex-replace(//strings/str2[3]/text(), 'r', '')"/>
  <log>*** REGEX FUNCTION: $regExFunction; ***</log>
    <wait value="1s"/>
  </block>

<!-- REPEAT -->
  <assign var="repeatFunction" expr="repeat( 'candyman ', 3 )"/>
  <log>*** REPEAT FUNCTION : $repeatFunction; ***</log>
    <wait value="1s"/>


<!-- STARTS WITH -->
  <assign var="startsWithFunction" expr="starts-with((//strings/str2[1]/text()), 'b')"/>
  <log>***  STARTS WITH FUNCTION $startsWithFunction; ***</log>

  <assign var="startsWithFunction" expr="starts-with((//strings/str2[1]/text()), 'z')"/>
  <log>***  STARTS WITH FUNCTION 2 $startsWithFunction; ***</log>
    <wait value="1s"/>


<!-- STRING LENGTH -->
  <block label="stringLengthFunction" value="$myFetch;">
  <assign var="stringLengthFunction" expr="string-length(//strings/str1[2]/text())"/>
  <log>***  STRING LENGTH FUNCTION: $stringLengthFunction; ***</log>
    <wait value="1s"/>



<!-- SUBSTRING -->
  <log>*** SUBSTRING FUNCTION 1: ***</log>
  <log expr="substring('footestpasses', '4')"/>
  <wait value="1s"/>

  <log>*** SUBSTRING FUNCTION 2: ***</log>
  <log expr="substring('footestpasses', '4', 8)"/>
    <wait value="1s"/>

  </block>

</callxml>


NumberFunctions.xml


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

<callxml version="3.0">

<!-- fetch our XML document, and assign it to a locally scoped CallXML variable -->
<fetch value="ConjunctionJunction.xml" var="myFetch" type="xml"/>


  <block label="NumberFunctions">

<!-- FLOOR -->
  <log>*** FLOOR FUNCTION floor:  ***</log>
  <log expr="floor(420.16)"/>
    <wait value="1s"/>

<!-- CEILING -->
  <log>*** CEILING FUNCTION:  ***</log>
  <log expr="ceiling(419.05)"/>
    <wait value="1s"/>

<!-- RANDOM -->
  <assign var="randomFunction" expr="random(99)"/>
  <log>***  RANDOM FUNCTION: $randomFunction; ***</log>
    <wait value="1s"/>

<!-- SUM -->
  <assign var="sumFunction" expr="sum(//numbers[1]/child::*/text())"/>
  <log>*** SUM FUNCTION: $sumFunction; ***</log>

  </block>

</callxml>


OtherFunctions.xml


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

<callxml version="3.0">

<!-- fetch our XML document, and assign it to a locally scoped CallXML variable -->
<fetch value="ConjunctionJunction.xml" var="myFetch" type="xml"/>


  <block label="otherFunction" value="$myFetch;">

<!-- TIME FUNCTION -->
  <assign var="timeFunction" expr="time()"/>
  <log>***  TIME FUNCTION: $timeFunction; ***</log>
    <wait value="1s"/>


<!-- TIMESTRING FUNCTION -->
  <assign var="timeStringFunction" expr="time-string()"/>
  <log>***  TIMESTRING FUNCTION: $timeStringFunction; ***</log>
    <wait value="1s"/>
  </block>

</callxml>



ConjunctionJunction.xml


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

<mynodes>
  <numbers>
    <digit>1</digit>
    <digit>2</digit>
    <digit>3</digit>
    <digit>10</digit>
    <digit>20</digit>
  </numbers>

  <booleans>
    <bool>true</bool>
    <bool>false</bool>
    <bool>99</bool>
  </booleans>

  <strings>
  <str1>starr</str1>
  <str1>swearengen</str1>
  <str2>bullock</str2>
  <str2>  ellsworth  </str2>
  <str2>dreadwood</str2>
  </strings>
</mynodes>


Download It!

If you'd rather just download the Xpath example files rather than typing them out yourself, then you must be government-employed. In any case, we aim to please, so you can grab the source files for the above code below, and upload it to your hosting server, (or ours), to give it a test run on the CallXML3.0 platform.


  CallXML 3.0 source code



  ACCOUNT LOGIN
Username:  
Password:  
  You must login with your Voxeo developer account prior to posting or editing your existing posts. If you aren't a member of Voxeo's developer community, click here to register.
  ANNOTATIONS: EXISTING POSTS
0 posts - click the button below to add a note to this page

  XPath Expressions: Part 2  |  TOC  |  I: CallXML Grammar Guide  

© 2013 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site