bug 54490, xsl:strip- and preserve-space need wildcards, r=sicking, peterv, sr=shaver
git-svn-id: svn://10.0.0.236/trunk@100786 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* 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
|
||||
@@ -587,22 +587,6 @@ Node* ProcessorState::popCurrentNode() {
|
||||
return currentNodeStack.pop();
|
||||
} //-- popCurrentNode
|
||||
|
||||
/**
|
||||
* Adds the set of names to the Whitespace preserving element set
|
||||
**/
|
||||
void ProcessorState::preserveSpace(String& names) {
|
||||
|
||||
//-- split names on whitespace
|
||||
Tokenizer tokenizer(names);
|
||||
String name;
|
||||
while ( tokenizer.hasMoreTokens() ) {
|
||||
tokenizer.nextToken(name);
|
||||
wsPreserve.add(new String(name));
|
||||
wsStrip.remove(name);
|
||||
}
|
||||
|
||||
} //-- preserveSpace
|
||||
|
||||
/**
|
||||
* Adds the given XSLT action to the top of the action stack
|
||||
**/
|
||||
@@ -664,16 +648,31 @@ void ProcessorState::setOutputMethod(const String& method) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the set of names to the Whitespace stripping element set
|
||||
* Adds the set of names to the Whitespace handling list.
|
||||
* xsl:strip-space calls this with MB_TRUE, xsl:preserve-space
|
||||
* with MB_FALSE
|
||||
**/
|
||||
void ProcessorState::stripSpace(String& names) {
|
||||
void ProcessorState::shouldStripSpace(String& names, MBool shouldStrip) {
|
||||
//-- split names on whitespace
|
||||
Tokenizer tokenizer(names);
|
||||
String name;
|
||||
while ( tokenizer.hasMoreTokens() ) {
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
tokenizer.nextToken(name);
|
||||
wsStrip.add(new String(name));
|
||||
wsPreserve.remove(name);
|
||||
txNameTestItem* nti = new txNameTestItem(name,shouldStrip);
|
||||
if (!nti) {
|
||||
// XXX error report, parsing error or out of mem
|
||||
break;
|
||||
}
|
||||
// XXX ToDo: get import precedence right, bug 83651
|
||||
double priority = nti->getDefaultPriority();
|
||||
txListIterator iter(&mWhiteNameTests);
|
||||
while (iter.hasNext()) {
|
||||
txNameTestItem* iNameTest = (txNameTestItem*)iter.next();
|
||||
if (iNameTest->getDefaultPriority() <= priority) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
iter.addBefore(nti);
|
||||
}
|
||||
|
||||
} //-- stripSpace
|
||||
@@ -785,10 +784,15 @@ MBool ProcessorState::isStripSpaceAllowed(Node* node) {
|
||||
|
||||
case Node::ELEMENT_NODE :
|
||||
{
|
||||
//-- check Whitespace element names against given Node
|
||||
// check Whitespace stipping handling list against given Node
|
||||
// XXX ToDo: get import precedence right, bug 83651
|
||||
String name = node->getNodeName();
|
||||
if (wsPreserve.contains(name)) return MB_FALSE;
|
||||
if (wsStrip.contains(name)) return MB_TRUE;
|
||||
txListIterator iter(&mWhiteNameTests);
|
||||
while (iter.hasNext()) {
|
||||
txNameTestItem* iNameTest = (txNameTestItem*)iter.next();
|
||||
if (iNameTest->matches(node,this))
|
||||
return iNameTest->stripsSpace();
|
||||
}
|
||||
String method;
|
||||
if (format.getMethod(method).isEqual("html")) {
|
||||
String ucName = name;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* 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
|
||||
@@ -243,9 +243,11 @@ public:
|
||||
void setOutputMethod(const String& method);
|
||||
|
||||
/**
|
||||
* Adds the set of names to the Whitespace stripping element set
|
||||
* Adds the set of names to the Whitespace stripping handling list.
|
||||
* xsl:strip-space calls this with MB_TRUE, xsl:preserve-space
|
||||
* with MB_FALSE
|
||||
**/
|
||||
void stripSpace(String& names);
|
||||
void shouldStripSpace(String& names, MBool shouldStrip);
|
||||
|
||||
/**
|
||||
* Adds a document to set of loaded documents
|
||||
@@ -392,17 +394,12 @@ private:
|
||||
OutputFormat format;
|
||||
|
||||
/**
|
||||
* The set of whitespace preserving elements
|
||||
* The list of whitespace preserving and stripping nametests
|
||||
**/
|
||||
StringList wsPreserve;
|
||||
txList mWhiteNameTests;
|
||||
|
||||
/**
|
||||
* The set of whitespace stripping elements
|
||||
**/
|
||||
StringList wsStrip;
|
||||
|
||||
/**
|
||||
* The set of whitespace stripping elements
|
||||
* Default whitespace stripping mode
|
||||
**/
|
||||
XMLSpaceMode defaultSpace;
|
||||
|
||||
@@ -451,6 +448,31 @@ private:
|
||||
|
||||
}; //-- ProcessorState
|
||||
|
||||
/**
|
||||
* txNameTestItem holds both an ElementExpr and a bool for use in
|
||||
* whitespace stripping.
|
||||
**/
|
||||
class txNameTestItem {
|
||||
public:
|
||||
txNameTestItem(String& aName, MBool stripSpace):
|
||||
mNameTest(aName),mStrips(stripSpace) {}
|
||||
|
||||
MBool matches(Node* aNode, ContextState* aCS) {
|
||||
return mNameTest.matches(aNode, 0, aCS);
|
||||
}
|
||||
|
||||
MBool stripsSpace() {
|
||||
return mStrips;
|
||||
}
|
||||
|
||||
double getDefaultPriority() {
|
||||
return mNameTest.getDefaultPriority(0, 0, 0);
|
||||
}
|
||||
|
||||
protected:
|
||||
ElementExpr mNameTest;
|
||||
MBool mStrips;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -538,7 +538,9 @@ void XSLTProcessor::processTopLevel(Document* aSource,
|
||||
err.append("xsl:preserve-space");
|
||||
notifyError(err);
|
||||
}
|
||||
else aPs->preserveSpace(elements);
|
||||
else {
|
||||
aPs->shouldStripSpace(elements, MB_FALSE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case XSLType::STRIP_SPACE :
|
||||
@@ -550,7 +552,9 @@ void XSLTProcessor::processTopLevel(Document* aSource,
|
||||
err.append("xsl:strip-space");
|
||||
notifyError(err);
|
||||
}
|
||||
else aPs->stripSpace(elements);
|
||||
else {
|
||||
aPs->shouldStripSpace(elements,MB_TRUE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user