module XsltDataTypes where import HdomParser import XPathDataTypes -- ----------------------------------------------------------------------------- type XsltRuleTree = NTree String type XsltRuleTrees = NTrees String -- | -- represents template rules with match attribute data XsltMatchRules = MRules [(XsltStep, XsltRuleDescr)] deriving (Show, Eq) -- | -- represents template rules with name attribute data XsltNameRules = NRules [(QName, Float, [NavXmlTree])] deriving (Show, Eq) data XsltStepList = StepList [XsltStep] deriving (Show) -- | -- represents StepPattern -- XsltToken represents list of nametests in elements attribute -- of xsl:strip-space and preserve-space data XsltStep = XsltRoot | XsltWildcard AxisSpec [Expr] | XsltTagName AxisSpec NodeTest [Expr] | XsltIdPattern Literal | XsltKeyPattern (Literal, Literal) | XsltError String | XsltParent | XsltAncestor | XsltToken QName deriving (Show, Eq) -- | -- represents a RuleDesriptor -- -- data XsltRuleDescr = RD { body :: XsltRulePriList ,parentRules :: XsltMatchRules ,ancestorRules :: XsltMatchRules } deriving (Show, Eq) data XsltRulePriList = RulePriList [(Priority, [NavXmlTree], Mode)] deriving (Show, Eq) type Mode = QName data Priority = Pri { priority :: Float ,importPri :: Float ,defPri :: Float } deriving (Ord, Show, Eq) data XsltRelPos = RelPos ([Int],XNode) deriving (Show, Eq) -- | -- -- data XsltStat = Stat { mode :: Mode ,currNode :: NavXmlTree ,currNodeList :: NavXmlTrees ,conPos :: Int ,conLen :: Int ,localVars :: XsltVarTab ,localParam :: XsltVarTab ,withParam :: XsltVarTab ,ruleBody :: NavXmlTree ,currRuleNode :: NavXmlTree } deriving (Show, Eq) -- | -- the result of all relevant functions to return result tree fragments -- or occurred errors data XsltResult = Res { errors :: [XsltError] ,resultNodes :: XmlTrees ,resultAttribs :: XmlTrees ,newVars :: XsltVarTab ,newParam :: XsltVarTab ,sortKeys :: [XsltSortKey] } deriving (Show, Eq) -- | -- the environment for the transformation -- contains the results of the top level elements, the source tree -- and all template rules data XsltEnv = Env { sourceNavTree :: NavXmlTree ,matchRules :: XsltMatchRules ,nameRules :: XsltNameRules ,xslNamespaces :: [String] ,globalVars :: XsltVarTab ,globalParam :: XsltVarTab ,stripSpace :: [(Priority, QName)] ,preserveSpace :: [(Priority, QName)] ,attSets :: [XsltAttribueSet] ,output :: XsltOutput ,decFormats :: [DecFormat] ,keyTable :: XsltKeyTab } data XsltNumFormat = NF { seperator :: String ,formLen :: Int ,formFct :: XsltFormatFct } data FormToken = SToken String | FToken String deriving (Show, Eq) type XsltError = String data XsltSortKey = SK { sortKey :: String ,lang :: String ,dataType :: String ,order :: String ,caseOrder :: String } deriving (Show, Eq) -- | -- type XsltFct = XsltEnv -> XsltStat -> XsltResult -> XsltResult type XsltTLFct = XsltStat -> (XsltEnv, XsltResult) -> (XsltEnv, XsltResult) type XsltFormatFct = (String -> Int -> Int -> Int -> String -> String) -- ----------------------------------------------------------------------------- type XsltVar = (QName, XPathValue) type XsltVarTab = [XsltVar] type XsltKeyTab = [(QName, String, NavXmlTree)] type XsltData = (XsltVarTab, XsltKeyTab) data XsltDataType = XsltVar | XsltGlobVar | XsltPara | XsltGlobPara | XsltAll deriving (Show, Eq) -- | -- represents all data of xsl:output element data XsltOutput = OUT { method :: QName ,version :: String -- nmtoken / VersionNum aus XSL-Spezi ,indent :: Bool ,encoding :: String ,mediaType :: String ,doctypeSys :: String ,doctypePub :: String ,omitXmlDec :: Bool ,standalone :: Bool ,cdataElems :: [QName] } deriving (Show, Eq) -- | -- represents attribute sets type XsltAttribueSet = (QName, [XsltAttribute]) data XsltAttribute = Att { attName :: QName ,attValue :: XmlTrees } deriving (Show, Eq) -- | -- represents all data of xsl:decimal-format data DecFormat = DecForm { formatName :: QName ,decSep :: String ,grpSep :: String ,infinity :: String ,minusSign :: String ,nan :: String ,perCent :: String ,perMille :: String ,zeroDigit :: String ,digit :: String ,patternSep :: String } deriving (Show, Eq) type NavXmlTreeFilter = (FilterValue -> NavXmlTree -> FilterValue) idNTFilter :: NavXmlTreeFilter idNTFilter fv _ = fv data FilterValue = QNameFV QName | StringFV String | BoolFV Bool -- ----------------------------------------------------------------------------- -- initial values for several types replace, notReplace :: Bool replace = True notReplace = False xsltInitVar :: XsltVarTab xsltInitVar = [(mkNSName "" "name" , XPVNumber NaN)] xsltInitData :: XsltData xsltInitData = ([(mkNSName "" "name" , XPVNumber NaN)], []) emptyResult :: XsltResult emptyResult = Res {errors = [], resultNodes = [], resultAttribs = [], newVars = [], newParam = [], sortKeys = []} --xsltInitVar} initEnv :: XsltEnv initEnv = Env { sourceNavTree = ntree emptyRoot ,matchRules = emptyMRule ,nameRules = emptyNRule ,xslNamespaces = ["xsl"] ,globalVars = [] --xsltInitVar ,globalParam = [] --xsltInitVar ,stripSpace = [] ,preserveSpace = [] ,attSets = [] ,output = initialOutput ,decFormats = [initialDecFormat] ,keyTable = [] } initStatus :: XsltStat initStatus = Stat { mode = mkNSName "" "" ,currNode = ntree emptyRoot ,currNodeList = [ntree emptyRoot] ,conPos = 1 ,conLen = 1 ,localVars = [] ,localParam = [] ,withParam = [] ,ruleBody = ntree emptyRoot ,currRuleNode = ntree emptyRoot } emptyRelPos :: XsltRelPos emptyRelPos = RelPos ([],(XText "")) emptyMRule :: XsltMatchRules emptyMRule = (MRules []) emptyRulePriList :: XsltRulePriList emptyRulePriList = (RulePriList []) emptyRD :: XsltRuleDescr emptyRD = RD { body = emptyRulePriList, parentRules = emptyMRule, ancestorRules = emptyMRule } emptyNRule :: XsltNameRules emptyNRule = (NRules []) initialPriority :: Priority initialPriority = Pri { priority = 0.0 ,importPri = 0.0 ,defPri = 0.0 } initialOutput :: XsltOutput initialOutput = OUT { method = mkNSName "" "xml" ,version = "1.0" ,indent = False ,encoding = "iso-8859-1" ,mediaType = "" ,doctypeSys = "" ,doctypePub = "" ,omitXmlDec = False ,standalone = True ,cdataElems = [] } initialDecFormat :: DecFormat initialDecFormat = DecForm { formatName = mkNSName "" "" ,decSep = "." ,grpSep = "," ,perCent = "%" ,perMille = "#x2030" ,zeroDigit = "0" ,digit = "#" ,patternSep = ";" ,infinity = "Infinity" ,minusSign = "-" ,nan = "NaN" }