parameters: (grd_node, str)
docstring: Helper function to conditionally inline inner elements
docstring_summary: Helper function to conditionally inline inner elements
docstring_tokens: Helper function to conditionally inline inner elements
function: def CheckConditionalElements(grd_node, str):
    def IsConditionSatisfied(src_match):
      expr1 = src_match.group('expr1') or ''
      expr2 = src_match.group('expr2') or ''
      return grd_node is None or grd_node.EvaluateCondition(expr1 + expr2)
  
    """Helper function to conditionally inline inner elements"""
    while True:
      begin_if = _BEGIN_IF_BLOCK.search(str)
      if begin_if is None:
        if _END_IF_BLOCK.search(str) is not None:
          raise Exception('Unmatched </if>')
        return str
  
      condition_satisfied = IsConditionSatisfied(begin_if)
      leading = str[0:begin_if.start()]
      content_start = begin_if.end()
  
      # Find matching "if" block end.
      count = 1
      pos = begin_if.end()
      while True:
        end_if = _END_IF_BLOCK.search(str, pos)
        if end_if is None:
          raise Exception('Unmatched <if>')
  
        next_if = _BEGIN_IF_BLOCK.search(str, pos)
        if next_if is None or next_if.start() >= end_if.end():
          count = count - 1
          if count == 0:
            break
          pos = end_if.end()
        else:
          count = count + 1
          pos = next_if.end()
  
      content = str[content_start:end_if.start()]
      trailing = str[end_if.end():]
  
      if condition_satisfied:
        str = leading + CheckConditionalElements(grd_node, content) + trailing
      else:
        str = leading + trailing
function_tokens: def CheckConditionalElements ( grd_node , str ) : def IsConditionSatisfied ( src_match ) : expr1 = src_match . group ( 'expr1' ) or '' expr2 = src_match . group ( 'expr2' ) or '' return grd_node is None or grd_node . EvaluateCondition ( expr1 + expr2 ) while True : begin_if = _BEGIN_IF_BLOCK . search ( str ) if begin_if is None : if _END_IF_BLOCK . search ( str ) is not None : raise Exception ( 'Unmatched </if>' ) return str condition_satisfied = IsConditionSatisfied ( begin_if ) leading = str [ 0 : begin_if . start ( ) ] content_start = begin_if . end ( ) # Find matching "if" block end. count = 1 pos = begin_if . end ( ) while True : end_if = _END_IF_BLOCK . search ( str , pos ) if end_if is None : raise Exception ( 'Unmatched <if>' ) next_if = _BEGIN_IF_BLOCK . search ( str , pos ) if next_if is None or next_if . start ( ) >= end_if . end ( ) : count = count - 1 if count == 0 : break pos = end_if . end ( ) else : count = count + 1 pos = next_if . end ( ) content = str [ content_start : end_if . start ( ) ] trailing = str [ end_if . end ( ) : ] if condition_satisfied : str = leading + CheckConditionalElements ( grd_node , content ) + trailing else : str = leading + trailing