if
The if statement provides conditional construction that
allows a set of templates to be processed based on an XPath expressio.
It does not provide an else function, however this is
simply done using the choose ... when ... otherwise ... statement.
Syntax
<if> ::= "if" <quote> <xpath expression> <quote>
"{"
<block elements>+
"}"
Options
None.
Elements
Although there are no required elements within the condition block, it is meaningless to have a condition that is null and does not return
any values (string characters).
Examples
The following example outputs the necessary <div> element to produce a breadcrumb panel when the \sqp{id}
attribute matches the variable gPage.
stylesheet {
version "1.0"
proc buildBody.htmlBody {
if "//breadcrumbs//list:item[@id = $gPage]" {
element "div" {
attribute "id" "breadcrumbPanel"
}
}
}
}
will result in
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
<template name="buildBody.htmlBody">
<if test="//breadcrumbs//list:item[@id = $gPage]">
<element name="div">
<attribute name="id">
<text>breadcrumbPanel</text>
</attribute>
</element>
</if>
</template>
</stylesheet>
Errors
Leaving out the test.
stylesheet {
version "1.0"
proc buildBody.htmlBody {
if {
element "div" {
attribute "id" "breadcrumbPanel"
}
}
}
}
will give the error
**** (122) Missing test expression in line 6
Insert test.
Copyright 2024 Hugh Field-Richards. All Rights Reserved.