-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-- stylesheet
-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
downloadXMLStyleSheet base stringHTML
    = do let html = parseTags stringHTML
             xmlTags = map (fromAttrib "href") $ filter (tagOpen (=="?xml-stylesheet") funAttrs) html
             xmlHref = Set.toList $ Set.fromList xmlTags    -- elimina los repetidos
             funName  = map getUrlFileName xmlHref
         mapM_ downloadprocess funName
    where funAttrs attrs = let pr1 = (=="href")
                               pr2 = [(\(n,v) -> n == "type" && v == "text/css")]
                               href   = any (pr1 . fst) attrs
                               others = and $ map (\f -> any f attrs) pr2
                           in href && others
          downloadprocess (url,name)
                = do css <- download base url
                     tmpDir <- retrieveTempDir
                     let path = tmpDir </> name
                     writeFile path css
                     putStrLn $ "File saved at " ++ path
                     return ()
downloadXMLStyleSheet base stringHTML
    = do let html = parseTags stringHTML
             xmlTags = map (fromAttrib "href") $ filter (tagOpen (=="?xml-stylesheet") funAttrs) html
             xmlHref = Set.toList $ Set.fromList xmlTags    -- elimina los repetidos
             funName  = map getUrlFileName xmlHref
         mapM_ downloadprocess funName
    where funAttrs attrs = let pr1 = (=="href")
                               pr2 = [(\(n,v) -> n == "type" && v == "text/css")]
                               href   = any (pr1 . fst) attrs
                               others = and $ map (\f -> any f attrs) pr2
                           in href && others
          downloadprocess (url,name)
                = do css <- download base url
                     tmpDir <- retrieveTempDir
                     let path = tmpDir </> name
                     writeFile path css
                     putStrLn $ "File saved at " ++ path
                     return ()
downloadXMLStyleSheet base stringHTML
    = do let html = parseTags stringHTML
             xmlTags = map (fromAttrib "href") $ filter (tagOpen (=="?xml-stylesheet") funAttrs) html
             xmlHref = Set.toList $ Set.fromList xmlTags    -- elimina los repetidos
             funName  = map getUrlFileName xmlHref
         mapM_ downloadprocess funName
    where funAttrs attrs = let pr1 = (=="href")
                               pr2 = [(\(n,v) -> n == "type" && v == "text/css")]
                               href   = any (pr1 . fst) attrs
                               others = and $ map (\f -> any f attrs) pr2
                           in href && others
          downloadprocess (url,name)
                = do css <- download base url
                     tmpDir <- retrieveTempDir
                     let path = tmpDir </> name
                     writeFile path css
                     putStrLn $ "File saved at " ++ path
                     return ()