diff --git a/Text/Hamlet/XML.hs b/Text/Hamlet/XML.hs
--- a/Text/Hamlet/XML.hs
+++ b/Text/Hamlet/XML.hs
@@ -10,7 +10,7 @@
 import qualified Data.Text.Lazy as TL
 import Control.Monad ((<=<))
 import Text.Hamlet.XMLParse
-import Text.Shakespeare.Base (readUtf8File, derefToExp, Scope, Deref (DerefIdent), Ident (Ident))
+import Text.Shakespeare.Base (readUtf8File, derefToExp, Scope, Deref, Ident (Ident))
 import Data.Text (pack, unpack)
 import qualified Data.Text as T
 import qualified Text.XML as X
@@ -18,6 +18,7 @@
 import qualified Data.Foldable as F
 import Data.Maybe (fromMaybe)
 import qualified Data.Map as Map
+import Control.Arrow (first)
 
 xml :: QuasiQuoter
 xml = QuasiQuoter { quoteExp = strToExp }
@@ -69,12 +70,13 @@
     [| maybe $(return nothing') $(return inside'') $(return deref') |]
 docToExp scope (DocCond conds final) = do
     unit <- [| () |]
-    body <- fmap GuardedB $ mapM go $ conds ++ [(DerefIdent $ Ident "otherwise", fromMaybe [] final)]
+    otherwise' <- [|otherwise|]
+    body <- fmap GuardedB $ mapM go $ map (first (derefToExp scope)) conds ++ [(otherwise', fromMaybe [] final)]
     return $ CaseE unit [Match (TupP []) body []]
   where
     go (deref, inside) = do
         inside' <- docsToExp scope inside
-        return (NormalG $ derefToExp scope deref, inside')
+        return (NormalG deref, inside')
 
 mkAttrs :: Scope -> [(Maybe Deref, String, [Content])] -> Q Exp
 mkAttrs _ [] = [| Map.empty |]
diff --git a/xml-hamlet.cabal b/xml-hamlet.cabal
--- a/xml-hamlet.cabal
+++ b/xml-hamlet.cabal
@@ -1,5 +1,5 @@
 Name:                xml-hamlet
-Version:             0.4.0.8
+Version:             0.4.0.9
 Synopsis:            Hamlet-style quasiquoter for XML content
 Homepage:            http://www.yesodweb.com/
 License:             BSD3
