DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20927>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20927 xalan-c: proposed patch to separate out getting stylesheet uri in processing instruction Summary: xalan-c: proposed patch to separate out getting stylesheet uri in processing instruction Product: XalanC Version: 1.5 Platform: All OS/Version: All Status: NEW Severity: Enhancement Priority: Other Component: XalanC AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] This patch is to separate out the code that gets the stylesheet uri in the processing instruction in the parsed source xml. This may seem trivial but is very useful if you want to see if you can use a precompiled stylesheet identified by the uri. For example: typedef map<XalanDOMString, const XalanCompiledStylesheet *> CompiledStylesheetMap; static CompiledStylesheetMap compiledStylesheets; int transform(const char *url, const XalanParsedSource *parsedXML) { XalanDOMString stylesheetURI; // get the stylesheet uri in PI if (XSLTEngineImpl::getStylesheetURIInPI(parsedXML->getDocument(), stylesheetURI) == true) { stylesheetURI = URISupport::getURLStringFromString(stylesheetURI, XalanDOMString(url)); const XalanCompiledStylesheet *theCompiledStylesheet = NULL; CompiledStylesheetMap::iterator i = compiledStylesheets.find(stylesheetURI); if (i == compiledStylesheets.end()) { if (theTransformer->compileStylesheet(stylesheetURI, theCompiledStylesheet) == 0) { compiledStylesheets.insert(pair<XalanDOMString, const XalanCompile dStylesheet *>(stylesheetURI, theCompiledStylesheet)); } else { return -1; } } else { theCompiledStylesheet = i->second; } theTransformer->transform(*parsedXML, theCompiledStylesheet, r, (XalanOutputHandlerType)xalanOutputHandler); } return 0; } ============= CUT HERE =========================== --- xml-xalan/c/src/XSLT/XSLTEngineImpl.hpp Wed Dec 11 17:53:01 2002 +++ xml-xalan/c/src/XSLT/XSLTEngineImpl.hpp Wed Jun 18 16:20:12 2003 @@ -1614,6 +1614,8 @@ { m_topLevelParams.clear(); } + static bool getStylesheetURIInPI(const XalanNode *sourceTree, + XalanDOMString &theStylesheetURI); private: --- xml-xalan/c/src/XSLT/XSLTEngineImpl.cpp Wed Feb 12 14:41:26 2003 +++ xml-xalan/c/src/XSLT/XSLTEngineImpl.cpp Wed Jun 18 16:20:56 2003 @@ -287,86 +287,20 @@ if(0 != sourceTree && m_stylesheetRoot == 0) { - // Didn't get a stylesheet from the input source, so look for a - // stylesheet processing instruction... - - // The PI must be a child of the document... - const XalanNode* child = sourceTree->getFirstChild(); - - XalanDOMString theCurrentToken; - XalanDOMString theStylesheetURI; - - bool isOK = false; - - while(child != 0 && isOK == false && theStylesheetURI.empty() == true) - { - if(XalanNode::PROCESSING_INSTRUCTION_NODE == child->getNodeType()) - { - const XalanDOMString& nodeName = child->getNodeName(); - - if(equals(nodeName, s_stylesheetNodeName)) - { - StringTokenizer tokenizer(child->getNodeValue(), s_piTokenizerString); - - while(tokenizer.hasMoreTokens() == true && (isOK == false || theStylesheetURI.empty() == true)) - { - tokenizer.nextToken(theCurrentToken); - - if(equals(theCurrentToken, s_typeString)) - { - tokenizer.nextToken(theCurrentToken); - - - const XalanDOMString::size_type theLength = - theCurrentToken.length(); - - if (theLength > 2) - { - theCurrentToken.erase(theLength - 1, 1); - theCurrentToken.erase(0, 1); - - if(equals(theCurrentToken, s_typeValueString1) || - equals(theCurrentToken, s_typeValueString2) || - equals(theCurrentToken, s_typeValueString3) || - equals(theCurrentToken, s_typeValueString4)) - { - isOK = true; - } - } - } - else if(equals(theCurrentToken, s_hrefString)) - { - tokenizer.nextToken(theCurrentToken); - - const XalanDOMString::size_type theLength = - theCurrentToken.length(); - - if (theLength > 2) - { - // Trim of the starting and trailing delimiters... - theStylesheetURI.assign(theCurrentToken, 1, theLength - 2); - } - } - } - } - } - - child = child->getNextSibling(); - } - - if (isOK == true && theStylesheetURI.empty() == false) - { - const XalanDOMChar* const pxch = inputSource.getSystemId(); - - const XalanDOMString sysid(pxch == 0 ? &s_dummyString : pxch); - - getStylesheetFromPIURL( - theStylesheetURI, - *sourceTree, - sysid, - true, - constructionContext); - } + // Didn't get a stylesheet from the input source, so look for a + // stylesheet processing instruction... + XalanDOMString theStylesheetURI; + if (getStylesheetURIInPI(sourceTree, theStylesheetURI) == true && + theStylesheetURI.empty() == false) { + const XalanDOMChar* const pxch = inputSource.getSystemId(); + const XalanDOMString sysid(pxch == 0 ? &s_dummyString : pxch); + getStylesheetFromPIURL( + theStylesheetURI, + *sourceTree, + sysid, + true, + constructionContext); + } } if(0 == m_stylesheetRoot) @@ -3432,5 +3366,73 @@ } +bool XSLTEngineImpl::getStylesheetURIInPI(const XalanNode *sourceTree, + XalanDOMString &theStylesheetURI) +{ + // The PI must be a child of the document... + const XalanNode* child = sourceTree->getFirstChild(); + + XalanDOMString theCurrentToken; + + bool isOK = false; + + while(child != 0 && isOK == false && theStylesheetURI.empty() == true) + { + if(XalanNode::PROCESSING_INSTRUCTION_NODE == child->getNodeType()) + { + const XalanDOMString& nodeName = child->getNodeName(); + + if(equals(nodeName, s_stylesheetNodeName)) + { + StringTokenizer tokenizer(child->getNodeValue(), s_piTokenizerString); + + while(tokenizer.hasMoreTokens() == true && (isOK == false || theStylesheetURI.empty() == true)) + { + tokenizer.nextToken(theCurrentToken); + + if(equals(theCurrentToken, s_typeString)) + { + tokenizer.nextToken(theCurrentToken); + + + const XalanDOMString::size_type theLength = + theCurrentToken.length(); + + if (theLength > 2) + { + theCurrentToken.erase(theLength - 1, 1); + theCurrentToken.erase(0, 1); + + if(equals(theCurrentToken, s_typeValueString1) || + equals(theCurrentToken, s_typeValueString2) || + equals(theCurrentToken, s_typeValueString3) || + equals(theCurrentToken, s_typeValueString4)) + { + isOK = true; + } + } + } + else if(equals(theCurrentToken, s_hrefString)) + { + tokenizer.nextToken(theCurrentToken); + + const XalanDOMString::size_type theLength = + theCurrentToken.length(); + + if (theLength > 2) + { + // Trim of the starting and trailing delimiters... + theStylesheetURI.assign(theCurrentToken, 1, theLength - 2); + } + } + } + } + } + + child = child->getNextSibling(); + } + + return isOK; +} XALAN_CPP_NAMESPACE_END
