from xml.dom import XMLNS_NAMESPACE
from xml.sax import ContentHandler
import xml.dom
from string import *
import re
import copy
import rng
from rng import *
from Ft.Xml import XPath, cDomlette
import Ft.Xml
from types import *
from xml.dom.ext.reader.Sax2 import XmlDomGenerator

"""
The contents of this file are subject to the Mozilla Public License  
Version 1.1 (the "License"); you may not use this file except in  
compliance with the License. 
You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
Software distributed under the License is distributed on an "AS IS"  
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the  
License for the specific language governing rights and limitations under  
the License. 

The Original Code is available at 
http://downloads.xmlschemata.org/python/xvif/

The Initial Developer of the Original Code is Eric van der Vlist. Portions  
created by Eric van der Vlist are Copyright (C) 2002. All Rights Reserved. 

Contributor(s): 
"""

                                                            
def transform(self, node):
    import FragmentFilter
    from xml.dom.ext.Dom2Sax import Dom2SaxParser
    rules = FragmentFilter.RulesLoader()
    parser = Dom2SaxParser()
    parser.setContentHandler(rules)
    parser.setFeature("http://xml.org/sax/features/namespaces", 1)
    parser.parse(self.applyElt.dom)
    fragFilter = FragmentFilter.FragmentFilter(rules)
    parser.setContentHandler(fragFilter)
    domg = XmlDomGenerator()
    domg.initState()
    fragFilter.setContentHandler(domg)
    try:
        parser.parse(node)
    except:
        return None
    #print "reg frag result: %s" % domg.getRootNode().childNodes[1]
    return domg.getRootNode().childNodes[1]
        
