When $search_do
is not defined, then it has not been declared (in the current scope).
It's a simple as that - there is no "conditional variable definition" in XSLT. They can't be sometimes defined and sometimes not, they are always the one or the other. An "is defined check" is completely unnecessary, that's why there is none. You can always see from your code if a variable is there or not.
Variables are strictly scoped, though. The are valid only in within their parent element. This means you can't do
<xsl:if test="some-condition">
<xsl:variable name="search_do" value="foo" />
<!-- search_do goes out of scope right away! -->
</xsl:if>
<!-- $search_do will not be valid here -->
<input type="text" name="search_do" value="{$search_do}" />
but rather
<xsl:if test="some-condition">
<xsl:variable name="search_do" value="foo" />
<!-- use it as long as it is in scope -->
<input type="text" name="search_do" value="{$search_do}" />
</xsl:if>