<else>

Else branch processor

Core v2.2.0

Overview

The processor executes when the preceding condition evaluates to false. Used with for conditional branching logic.

Usage Examples

Example 1: Simple if-else logic

example-1.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<if condition="${stock > 0}">
  <def var="status" value="In Stock"/>
</if>
<else>
  <def var="status" value="Out of Stock"/>
</else>
</config>

Example 2: Handle empty results

example-2.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<def var="title">
  <xpath expression="//h1/text()">
    <html-to-xml>${response}</html-to-xml>
  </xpath>
</def>

<if condition="${!empty(title)}">
  <file path="title.txt" action="write">${title}</file>
</if>
<else>
  <file path="errors.log" action="append">
    Title not found on page ${url}
  </file>
</else>
</config>

Example 3: Error handling with HTTP

example-3.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://org.webharvest/schema/2.1/core">
<def var="response">
  <try>
    <http url="https://api.example.com/data"/>
  </try>
  <catch>
    <empty/>
  </catch>
</def>

<if condition="${!empty(response)}">
  <!-- Process successful response -->
  <def var="data">
    <json-to-xml>${response}</json-to-xml>
  </def>
</if>
<else>
  <!-- Fallback to cached data -->
  <def var="data">
    <file path="cache/last-response.xml" action="read"/>
  </def>
</else>
</config>

Parameters

Important Notes

Related Processors