module Main(main) where import HdomParser import Xslt import System.IO import System import XsltDataTypes import Unicode -- ----------------------------------------------------------------------------- -- ----------------------------------------- -- examlpe-files from the book xslt, Doug Tidwell, O'Reilly --f1 = "greeting.xsl" --f2 = "greeting.xml" --f1 = "xpath-tree-diagram.xsl" -- ?? Program error: {foldr1 parseStr'_v3733 []} --f2 = "sonnet.xml" --f1 = "value-of.xsl" --f2 = "test3.xml" --f1 = "attribute.xsl" --f2 = "test4.xml" --f1 = "text.xsl" --f2 = "test4.xml" --f1 = "copy.xsl" --f2 = "test3.xml" --f1 = "copy-of.xsl" --f2 = "test2.xml" --f1 = "element.xsl" --f2 = "test3.xml" --f1 = "for-each.xsl" --f2 = "test2.xml" --f1 = "example_test1.xsl" --f2 = "test1.xml" --f1 = "processing-instruction.xsl" --f2 = "test2.xml" --f1 = "number.xsl" --f2 = "test5.xml" --f1 = "choose.xsl" --f2 = "test4.xml" --f1 = "param.xsl" --f2 = "test2.xml" --f1 = "attribute-set.xsl" --f2 = "test2.xml" --f1 = "strip-space.xsl" --f2 = "test7.xml" -- ----------------------------------------------------------------------------- -- beispiel fuer xsl:apply-templates f1 = "AE\\simple.xsl" f2 = "AE\\simple.xml" --f1 = "AE\\apply-templates.xsl" --f2 = "AE\\test1.xml" --f1 = "AE\\mode.xsl" --f2 = "AE\\mode.xml" --f1 = "AE\\value-of.xsl" --f2 = "AE\\test2.xml" --f1 = "AE\\call-template.xsl" --f2 = "AE\\test2.xml" --f1 = "AE\\element.xsl" --f2 = "AE\\test5.xml" --f1 = "AE\\attribute.xsl" --f2 = "AE\\test3.xml" --f1 = "AE\\text.xsl" --f2 = "AE\\test4.xml" --f1 = "AE\\comment.xsl" --f2 = "AE\\test0.xml" --f1 = "AE\\copy.xsl" --f2 = "AE\\test5.xml" --f1 = "AE\\variable.xsl" --f2 = "AE\\test0.xml" --f1 = "AE\\param.xsl" --f2 = "AE\\test0.xml" --f1 = "AE\\for-each.xsl" --f2 = "AE\\test3.xml" --f1 = "AE\\if.xsl" --f2 = "AE\\test3.xml" --f1 = "AE\\number.xsl" --f2 = "AE\\test6.xml" --f1 = "AE\\sort.xsl" --f2 = "AE\\test8.xml" --f1 = "AE\\decimal-format.xsl" --f2 = "AE\\test3.xml" --f1 = "AE\\strip-space.xsl" --f2 = "AE\\test9.xml" -- ----------------------------------------------------------------------------- --f1 = "TemplateTests\\template001.xsl" --f2 = "TemplateTests\\template001.xml" --f1 = "DataManipulationtests\\dataManipulation016.xsl" --f2 = "DataManipulationtests\\dataManipulation016.xml" -- ----------------------------------------------------------------------------- path1 = ".\\test_examples\\" path2 = ".\\xsl-xsltxpath\\" file = path1 ++ f1 file2 = path1 ++ f2 xsltDTD = ".\\stylesheet.dtd" -- | -- Main main :: IO () main = do -- | -- test parser with file run' $ runXsltExample (newRoot (xattr "source" file)) (newRoot (xattr "source" file2)) (newRoot (xattr "source" xsltDTD)) runXsltExample :: XmlTree -> XmlTree -> XmlTree -> XState state () runXsltExample xslDatei xmlDatei xslDTD = do xslRes <- (getWellformedDoc) xslDatei -- parse the xslt-document --xmlRes <- (getWellformedDoc .>> getValidatedDoc -- parse and validate the xml-document xmlRes <- (getWellformedDoc) xmlDatei xslDtdTree <- (getWellformedDoc) xslDTD if null xslRes || null xmlRes -- || null xslDtdTree then return () -- parse error occured else let -- XSLT-Datei xslRoot = canonicalizeAllNodes $ head xslRes xslCs1 = getChildren $ head xslRoot xslCs = propagateNamespaces $ head xslCs1 xslFile = xslCs -- XML-Datei xmlRoot = head xmlRes xmlCs = getChildren xmlRoot xmlFile = xmlRes -- | -- herausfiltern aller template-tags aus dem Stylesheet -- tags mit match-attribute -- allMatchRules = getMatchRules xslCs -- matchRulesBaum = getMatchRulesTree allMatchRules -- tags mit name-attribute -- allNameRules = getNameRules xslCs -- nameRulesBaum = getNameRulesTree allNameRules {- -- das xml-File in einen NavTree umwandeln rootNavTree = head (getNavTree "/" $$ xmlRes) -- NavTree in eine Liste von RelPos umwandeln rootTreePos = getRelPosTree rootNavTree --einstiegsPfad = "/doc/chapter/section[1]/title[position()=1]"
--einstiegsPfad = "/doc/chapter/section[2]/para" einstiegsPfad = "/doc" --einstiegsPfad = "/*[1]/*[5]" --passendeRules = fittingRules rootNavTree matchRules [1] -- einstiegsPfad -} -- ------------------------------------------------------------------- -- hier beginnt die hemmungslose testerei ....... -- ---------------------------------------------- --f = validateXslFile xslDtdTree xslFile f = xslFile --result = xslProcessStylesheet xmlFile xslFile (env,result) = xslProcessStylesheet xmlFile xslFile ergebnis = resultNodes result fehler = errors result -- -------------------------------------------- {- derTree = t5 printCurrentData = dataNT derTree printLinks = map dataNT (precedingSiblingAxis derTree) printRechts = map dataNT (followingSiblingAxis derTree) printParent = map dataNT (parentAxis derTree) printChilds = map dataNT (childAxis derTree) printAncestors = map dataNT (ancestorOrSelfAxis derTree) printDescendant = map dataNT (descendantAxis derTree) printAttributes = map dataNT (attributeAxis derTree) -} -- ------------------------------------------------------------------- -- Ausgabe der gesammelten Sachen -- ------------------------------- in -- of the content io $ ( do -- run the io command for showing the result -- putStrLn (if (length (getMRParseErrors allMatchRules) == 0) -- then "\nparse ... ok\n" -- else ("\nParse-Errors:\n" ++ (getMRParseErrors allMatchRules))) {- putStrLn "\n\nData:" --print currentData putStrLn (xshow [NTree printCurrentData []]) putStrLn "links:" ; print printLinks putStrLn "rechts:" ; print printRechts putStrLn "parent:" ; print printParent putStrLn "childs:" ; print printChilds putStrLn "ancestors or self:" ; print printAncestors putStrLn "descendant:" ; print printDescendant putStrLn "attributes:" ; print printAttributes putStrLn (xshow ([subtreeNT derTree])) -} putStrLn "\nergebnis:\n------------" --print ergebnis putStrLn (xshow ergebnis) putStrLn "------------" print fehler putStrLn "------------" --print (currPosInSource ergebnis) --print allMatchRules --print $ globalVars env --print $ sourceNavTree env --putStrLn (xshow f) --print f )