$WBXPATH - XPath

Availability
$WBXPATH is available for use with all WBSP commands.

Syntax
$WBXPATH{XMLSource|pattern|Namespaces}
$WBXPATH[XMLSource|pattern|Namespaces]

Parameters
XMLSource - String value containing XML to be searched. Note that this is not an URL of the XML file but XML source itself.
pattern - Any valid XPath pattern (). When using square brackets in pattern use $WBFN[CHR(91)] for left and $WBFN[CHR(93)] for right square bracket, or use escape characters .
Namespaces - optional parameter containing XML namespace(s) in form nsID=nsURI.


Returns
Value(s) of node(s) matching XPath pattern .

Example

[FormFields]
wb_command=R
<!--WB_BeginTemplate-->
<html>
<head>
    <title>Xpath</title>
</head>
<body>
$wbsetv[xml|$wbgeturl[xmlsample.xml]]
$wbsetv[loopcounter|1]
$WBWHILE[$wbgetv[loopcounter]<=3|
$wbxpath[$wbgetv[xml]|//codes/condition$wbfn[chr(91)]position() = $wbgetv[loopcounter]$wbfn[chr(93)]/description]<br>
$wbsetv[loopcounter|$wbcalc[$wbgetv[loopcounter]+1]]
]
</body>
</html>

File XMLSample.xml

<?xml version="1.0" encoding="UTF-8"?>
<codes>
  <condition>
    <code>XXX</code>
    <description>XXX description</description>
    <day_icon>XXXDayIcon.png</day_icon>
    <night_icon>XXXNightIcon.png</night_icon>
  </condition>
  <condition>
    <code>YYY</code>
    <description>YYY description</description>
    <day_icon>DayYYYIcon.png</day_icon>
    <night_icon>NightYYYIcon.png</night_icon>
  </condition>
  <condition>
    <code>ZZZ</code>
    <description>ZZZ description</description>
    <day_icon>DayIconZZZ.png</day_icon>
    <night_icon>NightIconZZZ.png</night_icon>
  </condition>
</codes>

After running this example, the resulting page in browser should look like this:

XXX description
YYY description
ZZZ description