コード例 #1
0
ファイル: core.py プロジェクト: muhkuh-sys/mbs
def xsltHeader(node, allowedNames=[]):
	"""xsltHeader iterates over nodes' children and stores 
	all children from XSLT namespace with allowedNames in elements list
	until it sees any disallowed node (that is not whitespace).
	Skipped whitespace nodes with any remainder of child nodes
	is called tail. xsltHeader returns a tuple (elements, tail)."""
	
	elements = []
	tail = []
		
	i = 0
	for i in range(node.childNodes.length):
		child = node.childNodes.item(i)
		if tools.isWhitespaceNode(child):
			tail.append(child)
				
		elif child.nodeType == xml.dom.Node.ELEMENT_NODE and \
				child.namespaceURI == XSLT_NAMESPACE and \
				child.localName in allowedNames:
			elements.append(child)
			
		else:
			tail.append(child)
			break
				
	for i in range(i+1, node.childNodes.length):
		tail.append(node.childNodes.item(i))
		
	return (elements, tail)
コード例 #2
0
ファイル: core.py プロジェクト: nfultz/pyxslt
def xsltHeader(node, allowedNames=[]):
    """xsltHeader iterates over nodes' children and stores 
	all children from XSLT namespace with allowedNames in elements list
	until it sees any disallowed node (that is not whitespace).
	Skipped whitespace nodes with any remainder of child nodes
	is called tail. xsltHeader returns a tuple (elements, tail)."""

    elements = []
    tail = []

    i = 0
    for i in range(node.childNodes.length):
        child = node.childNodes.item(i)
        if tools.isWhitespaceNode(child):
            tail.append(child)

        elif child.nodeType == xml.dom.Node.ELEMENT_NODE and \
          child.namespaceURI == XSLT_NAMESPACE and \
          child.localName in allowedNames:
            elements.append(child)

        else:
            tail.append(child)
            break

    for i in range(i + 1, node.childNodes.length):
        tail.append(node.childNodes.item(i))

    return (elements, tail)
コード例 #3
0
ファイル: core.py プロジェクト: muhkuh-sys/mbs
def xsltChildren(node, allowedNames=[]):
	"""Returns a list of all node's child elements
	from XSLT namespace with localName in allowedNames.
	If the node has any other child nodes that are node whitespace
	it raises UnexpectedNode"""
	
	if isinstance(node, list):
		children = node
	else:
		children = node.childNodes
		
	elements = []
	for child in children:
		if tools.isWhitespaceNode(child):
			pass #ignore
		elif child.nodeType == xml.dom.Node.ELEMENT_NODE and \
				child.namespaceURI == XSLT_NAMESPACE and \
				child.localName in allowedNames:
			elements.append(child)
		else:
			raise UnexpectedNode(i)
			
	return elements
コード例 #4
0
ファイル: core.py プロジェクト: nfultz/pyxslt
def xsltChildren(node, allowedNames=[]):
    """Returns a list of all node's child elements
	from XSLT namespace with localName in allowedNames.
	If the node has any other child nodes that are node whitespace
	it raises UnexpectedNode"""

    if isinstance(node, list):
        children = node
    else:
        children = node.childNodes

    elements = []
    for child in children:
        if tools.isWhitespaceNode(child):
            pass  #ignore
        elif child.nodeType == xml.dom.Node.ELEMENT_NODE and \
          child.namespaceURI == XSLT_NAMESPACE and \
          child.localName in allowedNames:
            elements.append(child)
        else:
            raise UnexpectedNode(i)

    return elements