You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by David Yan <da...@yahoo-inc.com> on 2003/06/19 01:33:46 UTC

xalan-c: proposed patch to separate out getting stylesheet uri in processing instruction

[ resending because it doesn't show up in mail archive ]

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

Re: xalan-c: proposed patch to separate out getting stylesheet uri in processing instruction

Posted by da...@us.ibm.com.



> 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.

Hi David,

Can you please create Bugzilla enhancements requests for anything you would
like to submit, so they don't get lost?  We can then take a look at them
and see whether or not we want to incorporate them.

Thanks!

Dave