I actually wrote a DP for this exact use case. See Approach 3 in Design Pattern: Encoding and Accessing Values in Rules.