mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Support LRE stylesheets
b=104052 r=peterv rs=brendan
This commit is contained in:
parent
338b1b278a
commit
d0c41534e0
@ -71,8 +71,10 @@ const String PROC_INST = "processing-instruction";
|
||||
const String PRESERVE_SPACE = "preserve-space";
|
||||
const String SORT = "sort";
|
||||
const String STRIP_SPACE = "strip-space";
|
||||
const String STYLESHEET = "stylesheet";
|
||||
const String TEMPLATE = "template";
|
||||
const String TEXT = "text";
|
||||
const String TRANSFORM = "transform";
|
||||
const String VALUE_OF = "value-of";
|
||||
const String VARIABLE = "variable";
|
||||
const String WHEN = "when";
|
||||
|
@ -68,9 +68,11 @@ extern const String PARAM;
|
||||
extern const String PROC_INST;
|
||||
extern const String PRESERVE_SPACE;
|
||||
extern const String STRIP_SPACE;
|
||||
extern const String STYLESHEET;
|
||||
extern const String SORT;
|
||||
extern const String TEMPLATE;
|
||||
extern const String TEXT;
|
||||
extern const String TRANSFORM;
|
||||
extern const String VALUE_OF;
|
||||
extern const String VARIABLE;
|
||||
extern const String WHEN;
|
||||
|
@ -211,7 +211,7 @@ void ProcessorState::addTemplate(Element* aXslTemplate,
|
||||
return;
|
||||
}
|
||||
templ->mTemplate = aXslTemplate;
|
||||
templ->mMatch = exprParser.createExpr(match);
|
||||
templ->mMatch = exprParser.createPatternExpr(match);
|
||||
if (templ->mMatch)
|
||||
templates->add(templ);
|
||||
else
|
||||
@ -219,6 +219,45 @@ void ProcessorState::addTemplate(Element* aXslTemplate,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds the given LRE Stylesheet to the list of templates to process
|
||||
* @param aStylesheet The Stylesheet to add as a template
|
||||
* @param importFrame ImportFrame to add the template to
|
||||
*/
|
||||
void ProcessorState::addLREStylesheet(Document* aStylesheet,
|
||||
ImportFrame* aImportFrame)
|
||||
{
|
||||
NS_ASSERTION(aStylesheet, "missing stylesheet");
|
||||
|
||||
// get the txList for null mode
|
||||
txList* templates =
|
||||
(txList*)aImportFrame->mMatchableTemplates.get(NULL_STRING);
|
||||
|
||||
if (!templates) {
|
||||
templates = new txList;
|
||||
if (!templates) {
|
||||
// XXX ErrorReport: out of memory
|
||||
return;
|
||||
}
|
||||
aImportFrame->mMatchableTemplates.put(NULL_STRING, templates);
|
||||
}
|
||||
|
||||
// Add the template to the list of templates
|
||||
MatchableTemplate* templ = new MatchableTemplate;
|
||||
if (!templ) {
|
||||
// XXX ErrorReport: out of memory
|
||||
return;
|
||||
}
|
||||
|
||||
templ->mTemplate = aStylesheet;
|
||||
String match("/");
|
||||
templ->mMatch = exprParser.createPatternExpr(match);
|
||||
if (templ->mMatch)
|
||||
templates->add(templ);
|
||||
else
|
||||
delete templ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given node to the result tree
|
||||
* @param node the Node to add to the result tree
|
||||
@ -400,14 +439,14 @@ List* ProcessorState::getImportFrames()
|
||||
* Finds a template for the given Node. Only templates with
|
||||
* a mode attribute equal to the given mode will be searched.
|
||||
*/
|
||||
Element* ProcessorState::findTemplate(Node* aNode,
|
||||
Node* aContext,
|
||||
const String& aMode)
|
||||
Node* ProcessorState::findTemplate(Node* aNode,
|
||||
Node* aContext,
|
||||
const String& aMode)
|
||||
{
|
||||
if (!aNode)
|
||||
return 0;
|
||||
|
||||
Element* matchTemplate = 0;
|
||||
Node* matchTemplate = 0;
|
||||
double currentPriority = Double::NEGATIVE_INFINITY;
|
||||
ImportFrame* frame;
|
||||
txListIterator frameIter(&mImportFrames);
|
||||
@ -422,8 +461,12 @@ Element* ProcessorState::findTemplate(Node* aNode,
|
||||
|
||||
MatchableTemplate* templ;
|
||||
while ((templ = (MatchableTemplate*)templateIter.next())) {
|
||||
String priorityAttr =
|
||||
templ->mTemplate->getAttribute(PRIORITY_ATTR);
|
||||
String priorityAttr;
|
||||
|
||||
if (templ->mTemplate->getNodeType() == Node::ELEMENT_NODE) {
|
||||
Element* elem = (Element*)templ->mTemplate;
|
||||
priorityAttr = elem->getAttribute(PRIORITY_ATTR);
|
||||
}
|
||||
|
||||
double tmpPriority;
|
||||
if (!priorityAttr.isEmpty()) {
|
||||
|
@ -122,6 +122,13 @@ public:
|
||||
**/
|
||||
void addTemplate(Element* aXslTemplate, ImportFrame* aImportFrame);
|
||||
|
||||
/*
|
||||
* Adds the given LRE Stylesheet to the list of templates to process
|
||||
* @param aStylesheet The Stylesheet to add as a template
|
||||
* @param importFrame ImportFrame to add the template to
|
||||
*/
|
||||
void addLREStylesheet(Document* aStylesheet, ImportFrame* aImportFrame);
|
||||
|
||||
/**
|
||||
* Adds the given Node to the Result Tree
|
||||
*
|
||||
@ -224,7 +231,7 @@ public:
|
||||
* Finds a template for the given Node. Only templates with
|
||||
* a mode attribute equal to the given mode will be searched.
|
||||
*/
|
||||
Element* findTemplate(Node* aNode, Node* aContext, const String& aMode);
|
||||
Node* findTemplate(Node* aNode, Node* aContext, const String& aMode);
|
||||
|
||||
/**
|
||||
* Determines if the given XSL node allows Whitespace stripping
|
||||
@ -389,7 +396,7 @@ private:
|
||||
};
|
||||
|
||||
struct MatchableTemplate {
|
||||
Element* mTemplate;
|
||||
Node* mTemplate;
|
||||
Pattern* mMatch;
|
||||
};
|
||||
|
||||
|
@ -394,19 +394,34 @@ Document* XSLTProcessor::process(istream& xmlInput, String& xmlFilename) {
|
||||
/**
|
||||
* Processes the Top level elements for an XSL stylesheet
|
||||
**/
|
||||
void XSLTProcessor::processTopLevel(Document* aSource,
|
||||
Document* aStylesheet,
|
||||
ListIterator* importFrame,
|
||||
ProcessorState* aPs)
|
||||
void XSLTProcessor::processStylesheet(Document* aSource,
|
||||
Document* aStylesheet,
|
||||
ListIterator* aImportFrame,
|
||||
ProcessorState* aPs)
|
||||
{
|
||||
NS_ASSERTION(aStylesheet, "processTopLevel called without stylesheet");
|
||||
if (!aStylesheet)
|
||||
if (!aStylesheet || !aStylesheet->getDocumentElement())
|
||||
return;
|
||||
|
||||
processTopLevel(aSource,
|
||||
aStylesheet->getDocumentElement(),
|
||||
importFrame,
|
||||
aPs);
|
||||
Element* elem = aStylesheet->getDocumentElement();
|
||||
|
||||
// This should be rewritten once ns-dom lands
|
||||
String prefix, localName, namespaceURI;
|
||||
XMLUtils::getNameSpace(elem->getNodeName(), prefix);
|
||||
XMLUtils::getLocalPart(elem->getNodeName(), localName);
|
||||
XMLDOMUtils::getNameSpace(prefix, elem, namespaceURI);
|
||||
|
||||
if ((localName.isEqual(STYLESHEET) || localName.isEqual(TRANSFORM)) &&
|
||||
namespaceURI.isEqual(XSLT_NS)) {
|
||||
processTopLevel(aSource, elem, aImportFrame, aPs);
|
||||
}
|
||||
else {
|
||||
NS_ASSERTION(aImportFrame->current(), "no current importframe");
|
||||
if (!aImportFrame->current())
|
||||
return;
|
||||
aPs->addLREStylesheet(aStylesheet,
|
||||
(ProcessorState::ImportFrame*)aImportFrame->current());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -657,7 +672,10 @@ void XSLTProcessor::processInclude(String& aHref,
|
||||
|
||||
switch(stylesheet->getNodeType()) {
|
||||
case Node::DOCUMENT_NODE :
|
||||
processTopLevel(aSource, (Document*)stylesheet, aImportFrame, aPs);
|
||||
processStylesheet(aSource,
|
||||
(Document*)stylesheet,
|
||||
aImportFrame,
|
||||
aPs);
|
||||
break;
|
||||
case Node::ELEMENT_NODE :
|
||||
processTopLevel(aSource, (Element*)stylesheet, aImportFrame, aPs);
|
||||
@ -705,7 +723,7 @@ Document* XSLTProcessor::process
|
||||
ListIterator importFrame(ps.getImportFrames());
|
||||
importFrame.addAfter(new ProcessorState::ImportFrame);
|
||||
importFrame.next();
|
||||
processTopLevel(&xmlDocument, &xslDocument, &importFrame, &ps);
|
||||
processStylesheet(&xmlDocument, &xslDocument, &importFrame, &ps);
|
||||
|
||||
//----------------------------------------/
|
||||
//- Process root of XML source document -/
|
||||
@ -751,7 +769,7 @@ void XSLTProcessor::process
|
||||
ListIterator importFrame(ps.getImportFrames());
|
||||
importFrame.addAfter(new ProcessorState::ImportFrame);
|
||||
importFrame.next();
|
||||
processTopLevel(&xmlDocument, &xslDocument, &importFrame, &ps);
|
||||
processStylesheet(&xmlDocument, &xslDocument, &importFrame, &ps);
|
||||
|
||||
//----------------------------------------/
|
||||
//- Process root of XML source document -/
|
||||
@ -976,7 +994,7 @@ void XSLTProcessor::process(Node* node,
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
Element* xslTemplate = ps->findTemplate(node, context, mode);
|
||||
Node* xslTemplate = ps->findTemplate(node, context, mode);
|
||||
if (xslTemplate)
|
||||
processTemplate(node, xslTemplate, ps);
|
||||
else
|
||||
@ -1078,7 +1096,8 @@ void XSLTProcessor::processAction
|
||||
|
||||
for (int i = 0; i < nodeSet->size(); i++) {
|
||||
Node* currNode = nodeSet->get(i);
|
||||
Element* xslTemplate = ps->findTemplate(currNode, node, mode);
|
||||
Node* xslTemplate;
|
||||
xslTemplate = ps->findTemplate(currNode, node, mode);
|
||||
if (xslTemplate) {
|
||||
ps->pushCurrentNode(currNode);
|
||||
processTemplate(currNode, xslTemplate, ps, actualParams);
|
||||
@ -1793,7 +1812,7 @@ void XSLTProcessor::processDefaultTemplate(Node* node,
|
||||
ps->getNodeSetStack()->push(nodeSet);
|
||||
for (int i = 0; i < nodeSet->size(); i++) {
|
||||
Node* currNode = nodeSet->get(i);
|
||||
Element* xslTemplate = ps->findTemplate(currNode, node, mode);
|
||||
Node* xslTemplate = ps->findTemplate(currNode, node, mode);
|
||||
if (xslTemplate) {
|
||||
ps->pushCurrentNode(currNode);
|
||||
processTemplate(currNode, xslTemplate, ps, NULL);
|
||||
@ -2082,7 +2101,7 @@ XSLTProcessor::TransformDocument(nsIDOMNode* aSourceDOM,
|
||||
ListIterator importFrame(ps->getImportFrames());
|
||||
importFrame.addAfter(new ProcessorState::ImportFrame);
|
||||
importFrame.next();
|
||||
processTopLevel(sourceDocument, xslDocument, &importFrame, ps);
|
||||
processStylesheet(sourceDocument, xslDocument, &importFrame, ps);
|
||||
|
||||
//---------------------------------------/
|
||||
//- Process root of XML source document -/
|
||||
|
@ -332,10 +332,10 @@ private:
|
||||
ProcessorState* ps,
|
||||
const String& mode);
|
||||
|
||||
void processTopLevel(Document* aSource,
|
||||
Document* aStylesheet,
|
||||
ListIterator* importFrame,
|
||||
ProcessorState* aPs);
|
||||
void processStylesheet(Document* aSource,
|
||||
Document* aStylesheet,
|
||||
ListIterator* aImportFrame,
|
||||
ProcessorState* aPs);
|
||||
|
||||
void processTopLevel(Document* aSource,
|
||||
Element* aStylesheet,
|
||||
|
Loading…
Reference in New Issue
Block a user