The queryxmlstring() function

Smartsite 7.9 - ...

The queryxmlstring() extension function queries the specified xml string using the specified xpath statement.

XML CopyCode image Copy Code
string exf:queryxmlstring(string xml, string xpath)
string exf:queryxmlstring(string xml, string xpath, string prefix, string namespace)

Parameters:

  • string xml: the xml (escaped) string to query.  
  • string xpath: the xpath statement.
  • string prefix (optional): the namespace prefix.
  • string namespace (optional): the namespace.

Example

XML CopyCode image Copy Code
<html xmlns="http://www.w3.org/1999/xhtml" 
 xmlns:xf="http://www.w3.org/2002/xforms" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:a="uri:localization" 
 xmlns:exf="http://smartsite.nl/namespaces/xforms/1.0">
 <head>
  <title>Example</title>
  <xf:model>
   <xf:instance>
    <data xmlns="">     
     <moddate xsi:type="xf:dateTime">2018-01-30T10:34:00.000</moddate>
     <resources><![CDATA[
      <data xmlns="uri:localization">
      <strings lang="nl-NL">
       <string code="TITLE">Titel</string>
       <string code="MODDATE">Wijzigingsdatum</string>
      </strings>
      <strings lang="en-US">
       <string code="TITLE">Title</string>
       <string code="MODDATE">Modification date</string>
      </strings>
      </data>
     ]]></resources>
    </data>
   </xf:instance>
  </xf:model>
 </head>
 <body>
  <xf:group ref="/data" appearance="full" xml:lang="nl-nl">
   <xf:label/>
   <xf:output value="exf:queryxmlstring(resources, concat('b:strings[@lang=&quot;', exf:lang(), '&quot;]/b:string[@code=&quot;TITLE&quot;]'),'b','uri:localization') " />
   <xf:output value="exf:queryxmlstring(resources, concat('b:strings[@lang=&quot;', exf:lang(), '&quot;]/b:string[@code=&quot;MODDATE&quot;]'),'b','uri:localization') " />
  </xf:group>
  <xf:group ref="/data" appearance="full" xml:lang="en-US">
   <xf:label/>
   <xf:output value="exf:queryxmlstring(resources, concat('b:strings[@lang=&quot;', exf:lang(), '&quot;]/b:string[@code=&quot;TITLE&quot;]'),'b','uri:localization') " />
   <xf:output value="exf:queryxmlstring(resources, concat('b:strings[@lang=&quot;', exf:lang(), '&quot;]/b:string[@code=&quot;MODDATE&quot;]'),'b','uri:localization') " />
  </xf:group>
 </body>
</html>

The result will be:

Titel
Wijzigingsdatum
Title
Modification date


Namespace

This function is available within the Smartsite XForms namespace (http://smartsite.nl/namespaces/xforms/1.0).