示例#1
0
XObjectPtr
FunctionFormatNumber::execute(
			XPathExecutionContext&	executionContext,
			XalanNode*				context,
			const XObjectPtr		arg1,
			const XObjectPtr		arg2,
			const LocatorType*		locator) const
{
	assert(arg1.null() == false && arg2.null() == false);	
	
	const double						theNumber = arg1->num();
	const XalanDOMString&				thePattern = arg2->str();
	
	typedef XPathExecutionContext::GetAndReleaseCachedString	GetAndReleaseCachedString;

	GetAndReleaseCachedString	theString(executionContext);

	executionContext.formatNumber(
			theNumber, 
			thePattern, 
			theString.get(), 
			context, 
			locator);	

	return executionContext.getXObjectFactory().createString(theString);
}
示例#2
0
/*
 * Get the total of the second and third arguments.
 */
inline double
getTotal(
			XalanDOMString::size_type	theSourceStringLength,
			double						theSecondArgValue,
			const XObjectPtr&			arg3)
{
	// Total the second and third arguments.  If the third argument is
	// missing, make it the length of the string + 1 (for XPath
	// indexing style).
	if (arg3.null() == true)
	{
		return double(theSourceStringLength + 1);
	}
	else
	{
		const double	theRoundedValue =
			DoubleSupport::round(DoubleSupport::add(theSecondArgValue, arg3->num()));

		// If there's overflow, then we should return the length of the string + 1.
		if (DoubleSupport::isPositiveInfinity(theRoundedValue) == true)
		{
			return double(theSourceStringLength + 1);
		}
		else
		{
			return theRoundedValue;
		}
	}
}
示例#3
0
XObjectPtr CExternalFunction::execute( XPathExecutionContext&   executionContext,
                                    XalanNode*              /* context */,
                                    const XObjectPtr        arg1,
                                    const Locator*          /* locator */) const
{
    assert(arg1.null() == false);
    const XalanDOMString& arg = arg1->str();

    //convert XalanDOMString (implemented as unsigned short*) into StringBuffer
    StringBuffer sbInput;
    sbInput.ensureCapacity(arg.length()+1);

    size32_t len = arg.length();
    for (size32_t i=0; i < len; i++)
        sbInput.append( (char) arg[i]);

    StringBuffer sbOutput;

    try
    {
        (*m_userFunction)(sbOutput, sbInput.str(), m_pTransform);
    }
    catch (IException* e)
    {
        StringBuffer msg;
        e->errorMessage(msg);
        e->Release();
    }
    catch (...)
    {
    }

    XalanDOMString xdsOutput( sbOutput.str() );
    return executionContext.getXObjectFactory().createString( xdsOutput );
}
XObjectPtr
FunctionLang::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              context,
            const XObjectPtr        arg1,
            const LocatorType*      /* locator */) const
{
    assert(arg1.null() == false);   

    const XalanNode*        parent = context;

    bool                    fMatch = false;

    const XalanDOMString&   lang = arg1->str();

    while(0 != parent)
    {
        if(XalanNode::ELEMENT_NODE == parent->getNodeType())
        {
            const XalanElement* const   theElementNode =
#if defined(XALAN_OLD_STYLE_CASTS)
                (const XalanElement*)parent;
#else
                static_cast<const XalanElement*>(parent);
#endif

            const XalanDOMString&       langVal =
                theElementNode->getAttributeNS(
                    DOMServices::s_XMLNamespaceURI,
                    s_attributeName);

            if(0 != length(langVal))
            {
                XPathExecutionContext::GetAndReleaseCachedString theGuard1(executionContext);
                XPathExecutionContext::GetAndReleaseCachedString theGuard2(executionContext);

                if(startsWith(toLowerCaseASCII(langVal, theGuard1.get()), toLowerCaseASCII(lang, theGuard2.get())))
                {
                    const XalanDOMString::size_type     valLen = length(lang);

                    if(length(langVal) == valLen ||
                       charAt(langVal, valLen) == XalanUnicode::charHyphenMinus)
                    {
                        fMatch = true;

                        break;
                    }
                }
            }
        }

        parent = DOMServices::getParentOfNode(*parent);
    }

    return executionContext.getXObjectFactory().createBoolean(fMatch);
}
示例#5
0
XObjectPtr
FunctionSubstring::execute(
			XPathExecutionContext&	executionContext,
			XalanNode*				context,
			const XObjectPtr		arg1,
			const XObjectPtr		arg2,
			const LocatorType*		locator) const
{
	assert(arg1.null() == false && arg2.null() == false);

	return execute(executionContext, context, arg1, arg2, s_nullXObjectPtr, locator);
}
XObjectPtr
FunctionElementAvailable::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              /* context */,          
            const XObjectPtr        arg1,
            const LocatorType*      locator) const
{
    assert(arg1.null() == false);

    return executionContext.getXObjectFactory().createBoolean(
        executionContext.elementAvailable(arg1->str(), locator));
}
示例#7
0
XObjectPtr
FunctionSubstringBefore::execute(
			XPathExecutionContext&	executionContext,
			XalanNode*				/* context */,
			const XObjectPtr		arg1,
			const XObjectPtr		arg2,
			const LocatorType*		/* locator */) const
{
	assert(arg1.null() == false && arg2.null() == false);

	const XalanDOMString&				theFirstString = arg1->str();

	const XalanDOMString::size_type		theFirstStringLength = length(theFirstString);

	if (theFirstStringLength == 0)
	{
		return createEmptyString(executionContext);
	}
	else
	{
		const XalanDOMString&				theSecondString = arg2->str();

		const XalanDOMString::size_type		theSecondStringLength = length(theSecondString);

		if (theSecondStringLength == 0)
		{
			return createEmptyString(executionContext);
		}
		else
		{
			const XalanDOMString::size_type		theIndex = indexOf(theFirstString,
													   theSecondString);

			if (theIndex == theFirstStringLength)
			{
				return createEmptyString(executionContext);
			}
			else
			{
				XPathExecutionContext::GetAndReleaseCachedString	theResult(executionContext);

				XalanDOMString&		theString = theResult.get();

				theString.assign(
						toCharArray(theFirstString),
						theIndex);

				// Create a string of the appropriate length...
				return executionContext.getXObjectFactory().createString(theResult);
			}
		}
	}
}
bool
TestStringResult(
            XPathProcessor&             theXPathProcessor,
            XPath&                      theXPath,
            XPathConstructionContext&   theXPathConstructionContext,
            const XalanDOMString&       theXPathString,
            PrintWriter&                thePrintWriter,
            const XalanDOMString&       theExpectedResult,
            XalanNode*                  theContextNode,
            const PrefixResolver&       thePrefixResolver,
            const NodeRefListBase&      theContextNodeList,
            XPathExecutionContext&      theExecutionContext)
{
    bool    fError = false;

    const XObjectPtr theResult =
        ExecuteXPath(
            theXPathProcessor,
            theXPathConstructionContext,
            theXPath,
            theXPathString,
            theContextNode,
            thePrefixResolver,
            theContextNodeList,
            theExecutionContext);

    thePrintWriter.print("Execution of XPath ");
    thePrintWriter.print(theXPathString);

    if (equals(theResult->str(), theExpectedResult) == true)
    {
        thePrintWriter.println(" succeeded.");
        thePrintWriter.print("The result was \"");
        thePrintWriter.print(theResult->str());
        thePrintWriter.println("\".");
    }
    else
    {
        fError = true;

        thePrintWriter.println(" failed!");
        thePrintWriter.print("The expected result was \"");
        thePrintWriter.print(theExpectedResult);
        thePrintWriter.println("\".");
        thePrintWriter.print("The actual result was \"");
        thePrintWriter.print(theResult->str());
        thePrintWriter.println("\".");
    }

    return fError;
}
示例#9
0
XObjectPtr
FunctionStartsWith::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              /* context */,
            const XObjectPtr        arg1,
            const XObjectPtr        arg2,
            const Locator* const    /* locator */) const
{
    assert(arg1.null() == false && arg2.null() == false);   

    const bool  fStartsWith =
        startsWith(
            arg1->str(executionContext), 
            arg2->str(executionContext));

    return executionContext.getXObjectFactory().createBoolean(fStartsWith);
}
XObjectPtr
FunctionString::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              /* context */,          
            const XObjectPtr        arg1,
            const LocatorType*      /* locator */) const
{
    assert(arg1.null() == false);   

    if (arg1->getType() == XObject::eTypeString)
    {
        // Since XObjects are reference counted, just return the
        // argument.
        return arg1;
    }
    else
    {
        return executionContext.getXObjectFactory().createStringAdapter(arg1);
    }
}
示例#11
0
XObjectPtr
FunctionGenerateID::execute(
			XPathExecutionContext&	executionContext,
			XalanNode*				/* context */,
			const XObjectPtr		arg1,
			const LocatorType*		locator) const
{
	assert(arg1.null() == false);

	const NodeRefListBase&	theNodeList = arg1->nodeset();

	if (theNodeList.getLength() == 0)
	{
		return executionContext.getXObjectFactory().createStringReference(s_emptyString);
	}
	else
	{
		return execute(executionContext, theNodeList.item(0), locator);
	}
}
示例#12
0
void
ElemVariable::execute(StylesheetExecutionContext&	executionContext) const
{
	assert(m_qname != 0);

	ParentType::execute(executionContext);

	const XObjectPtr	theValue(getValue(executionContext, executionContext.getCurrentNode()));

	if (theValue.null() == false)
	{
		executionContext.pushVariable(
				*m_qname,
				theValue,
				getParentNodeElem());
	}
	else
	{
		executionContext.pushVariable(
				*m_qname,
				this,
				getParentNodeElem());
	}
}
示例#13
0
XObjectPtr
FunctionSample::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              /* context */,          
            const XObjectPtr        arg1,
            const XObjectPtr        arg2,
            const Locator*          /* locator */) const
{
   assert(arg1.null() == false);
   assert(arg2.null() == false);

   XalanDOMString path;
   arg1->str(path);
   const bool bLinux = arg2->boolean();

   XalanDOMChar dchOld;
   XalanDOMChar dchNew;

   if (bLinux)
   {
      dchOld = '\\';
      dchNew = '/';
   }
   else
   {
      dchOld = '/';
      dchOld = '\\';
   }

    int len = path.length();
   for (int i=0; i<len; i++)
      if (path[i] == dchOld)
         path[i] = dchNew;

    return executionContext.getXObjectFactory().createString(path); 
}
示例#14
0
void
ElemForEach::selectAndSortChildren(
			StylesheetExecutionContext&		executionContext,
			const ElemTemplateElement*		theTemplate,
			NodeSorter*						sorter,
			int								selectStackFrameIndex) const
{
	typedef StylesheetExecutionContext::SetAndRestoreCurrentStackFrameIndex		SetAndRestoreCurrentStackFrameIndex;

	assert(m_selectPattern != 0);

	typedef XPathExecutionContext::BorrowReturnMutableNodeRefList	BorrowReturnMutableNodeRefList;

	BorrowReturnMutableNodeRefList	theGuard(executionContext);

	const NodeRefListBase*	sourceNodes = 0;

	XObjectPtr				xobjectResult;

	{
		SetAndRestoreCurrentStackFrameIndex		theSetAndRestore(
					executionContext,
					selectStackFrameIndex);

		xobjectResult = m_selectPattern->execute(
						*this,
						executionContext,
						*theGuard);

		if (xobjectResult.null() == true)
		{
			sourceNodes = &*theGuard;
		}
		else
		{
			theGuard.release();

			sourceNodes = &xobjectResult->nodeset();
		}
	}

	if(0 != executionContext.getTraceListeners())
	{
		executionContext.fireSelectEvent(
				SelectionEvent(
					executionContext, 
					executionContext.getCurrentNode(),
					*this,
					StaticStringToDOMString(XALAN_STATIC_UCODE_STRING("select")),
					*m_selectPattern,
					*sourceNodes));
	}

	const NodeRefListBase::size_type	nNodes = sourceNodes->getLength();

	if (nNodes > 0)
	{
		// If there's not NodeSorter, or we've only selected one node,
		// then just do the transform...
		if (sorter == 0 || nNodes == 1)
		{
			transformSelectedChildren(
				executionContext,
				theTemplate,
				*sourceNodes,
				nNodes);
		}
		else
		{
			typedef StylesheetExecutionContext::SetAndRestoreCurrentStackFrameIndex		SetAndRestoreCurrentStackFrameIndex;
			typedef StylesheetExecutionContext::ContextNodeListPushAndPop				ContextNodeListPushAndPop;
			typedef StylesheetExecutionContext::BorrowReturnMutableNodeRefList			BorrowReturnMutableNodeRefList;

			BorrowReturnMutableNodeRefList	sortedSourceNodes(executionContext);

			*sortedSourceNodes = *sourceNodes;

			{
				SetAndRestoreCurrentStackFrameIndex		theStackFrameSetAndRestore(
						executionContext,
						selectStackFrameIndex);

				ContextNodeListPushAndPop	theContextNodeListPushAndPop(
						executionContext,
						*sourceNodes);

				sorter->sort(executionContext, *sortedSourceNodes);
			}

			transformSelectedChildren(
				executionContext,
				theTemplate,
				*sortedSourceNodes,
				nNodes);
		}
	}
}
示例#15
0
	XalanDocumentFragmentXNodeSetBaseProxy(const XObjectPtr&	theXObject) :
		XNodeSetBase(),
		m_xobject(theXObject),
		m_proxy(theXObject->rtree())
	{
	}
bool
TestBooleanResult(
            XPathProcessor&             theXPathProcessor,
            XPath&                      theXPath,
            XPathConstructionContext&   theXPathConstructionContext,
            const XalanDOMString&       theXPathString,
            PrintWriter&                thePrintWriter,
            bool                        theExpectedResult,
            XalanNode*                  theContextNode,
            const PrefixResolver&       thePrefixResolver,
            const NodeRefListBase&      theContextNodeList,
            XPathExecutionContext&      theExecutionContext)
{
    bool    fError = false;

    const XObjectPtr theResult =
        ExecuteXPath(
            theXPathProcessor,
            theXPathConstructionContext,
            theXPath,
            theXPathString,
            theContextNode,
            thePrefixResolver,
            theContextNodeList,
            theExecutionContext);

    bool    fDump = false;

    if (fDump == true)
    {
        thePrintWriter.println();
        thePrintWriter.println();
        theXPath.getExpression().dumpOpCodeMap(thePrintWriter);
        thePrintWriter.println();
        theXPath.getExpression().dumpTokenQueue(thePrintWriter);
        thePrintWriter.println();
        thePrintWriter.println();
    }

    thePrintWriter.print("Execution of XPath ");
    thePrintWriter.print(theXPathString);

    if (theResult->boolean() == theExpectedResult)
    {
        thePrintWriter.println(" succeeded.");
        thePrintWriter.print("The result was ");
        thePrintWriter.print(theResult->boolean());
        thePrintWriter.println(".");
    }
    else
    {
        fError = true;

        thePrintWriter.println(" failed!");
        thePrintWriter.print("The expected result was \"");
        thePrintWriter.print(theExpectedResult);
        thePrintWriter.println("\".");
        thePrintWriter.print("The actual result was \"");
        thePrintWriter.print(theResult->boolean());
        thePrintWriter.println("\".");
    }

    return fError;
}
XalanNode*
FindContextNode(
            XPathProcessor&         theXPathProcessor,
            XPathEnvSupport&        theXPathEnvSupport,
            DOMSupport&             theDOMSupport,
            XPathFactory&           theXPathFactory,
            XalanDocument*          theDocument,
            const XalanDOMString&   theContextNodeMatchPattern,
            PrintWriter&            thePrintWriter,
            XPathExecutionContext&  theExecutionContext)
{
    XalanNode*      theResult = 0;

    MemoryManagerType&      theMemoryManager =
        theExecutionContext.getMemoryManager();

    XPath* const    theXPath = theXPathFactory.create();

    XPathConstructionContextDefault     theXPathConstructionContext;

    XPathGuard      theGuard(
                        theXPathFactory,
                        theXPath);

    XalanElement*               theNamespaceContext = 0;
    ElementPrefixResolverProxy  thePrefixResolver(theNamespaceContext, theXPathEnvSupport, theDOMSupport);
    NodeRefList                 theContextNodeList(theMemoryManager);

    const XObjectPtr    theXObject =
        ExecuteXPath(
            theXPathProcessor,
            theXPathConstructionContext,
            *theXPath,
            theContextNodeMatchPattern,
            theDocument,
            thePrefixResolver,
            theContextNodeList,
            theExecutionContext);

    try
    {
        assert(theXObject.null() == false);

        const NodeRefListBase&  theResultList =
                        theXObject->nodeset();

        if (theResultList.getLength() == 0)
        {
            thePrintWriter.print("FindContextNode: Unable to find context node using select \"");
            thePrintWriter.print(theContextNodeMatchPattern);
            thePrintWriter.println("\".");
            thePrintWriter.println("FindContextNode: No nodes matched the pattern.");
        }
        else if (theResultList.getLength() != 1)
        {
            thePrintWriter.print("FindContextNode: Unable to find context node using select \"");
            thePrintWriter.print(theContextNodeMatchPattern);
            thePrintWriter.println("\".");
            thePrintWriter.println("FindContextNode: More than one node matched the pattern.");
        }
        else
        {
            theResult = theResultList.item(0);
        }
    }
    catch(...)
    {
        thePrintWriter.print("FindContextNode: Error executing match pattern \"");
        thePrintWriter.print(theContextNodeMatchPattern);
        thePrintWriter.println("\".");
    }

    return theResult;
}
示例#18
0
void display()
{
  try
  {
    Render::start();
    Render::LIGHT->on();

    static double t = 0.0;
    t += 0.03333;

    GLfloat amb[4] = {0.25f, 0.20f, 0.07f, 1.f};
    GLfloat dif[4] = {0.75f, 0.61f, 0.23f, 1.f};
    GLfloat spe[4] = {0.63f, 0.56f, 0.37f, 1.f};
    GLfloat shine = 51.2f;

    glTranslated(0.0, 1.0, 0.0);
    glRotated(90.0, 1.0, 0.0, 0.0);
    Material::setMaterial(amb, dif, spe, shine);
    glutSolidTeapot(0.1);

    std::string path = "/home/daichi/Work/catkin_ws/src/ahl_ros_pkgs/ahl_common/wrapper/gl_wrapper/blender/";
    static XObjectPtr lwr1 = XObjectPtr(new XObject(path + "lwr07.x"));
    static XObjectPtr lwr2 = XObjectPtr(new XObject(path + "lwr07.x"));
    static XObjectPtr lwr3 = XObjectPtr(new XObject(path + "lwr07.x"));
    static SimpleObjectPtr grid = SimpleObjectPtr(new Grid(20, 20, 0.5));

    lwr1->setEulerZYX(std::string("Link01"), M_PI * std::sin(2.0 * M_PI * 0.1 * t), 0.0, 0.0);
    lwr1->setEulerZYX(std::string("Link02"), 0.0, 0.35 * M_PI * std::sin(2.0 * M_PI * 0.3 * t), 0.0);
    lwr1->setEulerZYX(std::string("Link03"), 0.5 * M_PI * std::sin(2.0 * M_PI * 0.2 * t), 0.0, 0.0);
    lwr1->setEulerZYX(std::string("Link04"), 0.0, 0.5 * M_PI * std::sin(2.0 * M_PI * 0.2 * t), 0.0);
    lwr1->setEulerZYX(std::string("Link05"), 0.4 * M_PI * std::sin(2.0 * M_PI * 0.3 * t), 0.0, 0.0);
    lwr1->setEulerZYX(std::string("Link06"), 0.0, 0.5 * M_PI * std::sin(2.0 * M_PI * 0.3 * t), 0.0);
    lwr1->setEulerZYX(std::string("EndEffector"), M_PI * std::sin(2.0 * M_PI * 0.6 * t), 0.0, 0.0);

    lwr2->setEulerZYX(std::string("Link01"), M_PI * std::sin(2.0 * M_PI * 0.1 * t), 0.0, 0.0);
    lwr2->setEulerZYX(std::string("Link02"), 0.0, 0.35 * M_PI * std::sin(2.0 * M_PI * 0.3 * t), 0.0);
    lwr2->setEulerZYX(std::string("Link03"), 0.5 * M_PI * std::sin(2.0 * M_PI * 0.2 * t), 0.0, 0.0);
    lwr2->setEulerZYX(std::string("Link04"), 0.0, 0.5 * M_PI * std::sin(2.0 * M_PI * 0.2 * t), 0.0);
    lwr2->setEulerZYX(std::string("Link05"), 0.4 * M_PI * std::sin(2.0 * M_PI * 0.3 * t), 0.0, 0.0);
    lwr2->setEulerZYX(std::string("Link06"), 0.0, 0.5 * M_PI * std::sin(2.0 * M_PI * 0.3 * t), 0.0);
    lwr2->setEulerZYX(std::string("EndEffector"), M_PI * std::sin(2.0 * M_PI * 0.6 * t), 0.0, 0.0);


    lwr3->setEulerZYX(std::string("Link01"), M_PI * std::sin(2.0 * M_PI * 0.1 * t), 0.0, 0.0);
    lwr3->setEulerZYX(std::string("Link02"), 0.0, 0.35 * M_PI * std::sin(2.0 * M_PI * 0.3 * t), 0.0);
    lwr3->setEulerZYX(std::string("Link03"), 0.5 * M_PI * std::sin(2.0 * M_PI * 0.2 * t), 0.0, 0.0);
    lwr3->setEulerZYX(std::string("Link04"), 0.0, 0.5 * M_PI * std::sin(2.0 * M_PI * 0.2 * t), 0.0);
    lwr3->setEulerZYX(std::string("Link05"), 0.4 * M_PI * std::sin(2.0 * M_PI * 0.3 * t), 0.0, 0.0);
    lwr3->setEulerZYX(std::string("Link06"), 0.0, 0.5 * M_PI * std::sin(2.0 * M_PI * 0.3 * t), 0.0);
    lwr3->setEulerZYX(std::string("EndEffector"), M_PI * std::sin(2.0 * M_PI * 0.6 * t), 0.0, 0.0);

    glLoadIdentity();
    lwr1->display();

    glLoadIdentity();
    glTranslated(0.0, -0.6, 0.0);
    lwr2->display();

    glLoadIdentity();
    glTranslated(0.0, -1.2, 0.0);
    lwr3->display();

    glLoadIdentity();
    grid->setColor(0, 0, 255);
    grid->setPosition(0.0, 0.0, 0.0);
    grid->display();
/*
    gl_wrapper::RightHandPtr right_hand;
    right_hand = RightHandPtr(new RightHand("/home/daichi/work/catkin_ws/src/gl_wrapper/righthand.cfg"));
    right_hand->display();
*/
    Render::end();
  }
  catch(Exception& e)
  {
    ROS_ERROR_STREAM(e.what());
    exit(1);
  }
  catch(FatalException& e)
  {
    ROS_ERROR_STREAM(e.what());
    exit(1);
  }
  catch(std::exception& e)
  {
    ROS_ERROR_STREAM(e.what());
    exit(1);
  }
  catch(...)
  {
    ROS_ERROR_STREAM("display : Unknown exception was thrown.");
    exit(1);
  }
}
bool
TestAxisResult(
            XPathProcessor&         theXPathProcessor,
            XPathEnvSupport&        theXPathEnvSupport,
            DOMSupport&             theDOMSupport,
            XMLParserLiaison&       theLiaison,
            XPathFactory&           theXPathFactory,
            const XalanDOMString&   theXMLFileURL,
            const XalanDOMString&   theXSLFileURL,
            PrintWriter&            thePrintWriter,
            XPathExecutionContext&  theExecutionContext)
{
    bool                    fError = false;

    XalanDocument* const    theXMLDocument = ParseXML(theLiaison,
                                                      theXMLFileURL);

    MemoryManagerType&      theMemoryManager =
        theExecutionContext.getMemoryManager();

    if (theXMLDocument != 0)
    {
        XalanDOMString      theContextNodeMatchPattern(theMemoryManager);
        XalanDOMString      theXPathString(theMemoryManager);

        if (GetXSLInput(theLiaison,
                        theXSLFileURL,
                        theContextNodeMatchPattern,
                        theXPathString,
                        theMemoryManager) == true)
        {
            XalanNode* const    theContextNode =
                FindContextNode(theXPathProcessor,
                                theXPathEnvSupport,
                                theDOMSupport,
                                theXPathFactory,
                                theXMLDocument,
                                theContextNodeMatchPattern,
                                thePrintWriter,
                                theExecutionContext);

            if (theContextNode != 0)
            {
                XalanElement* const             theNamespaceContext = 0;
                ElementPrefixResolverProxy      thePrefixResolver(theNamespaceContext, theXPathEnvSupport, theDOMSupport);
                NodeRefList                     theContextNodeList(theMemoryManager);

                XPath* const    theXPath = theXPathFactory.create();

                XPathConstructionContextDefault     theXPathConstructionContext(theMemoryManager);

                XPathGuard      theGuard(theXPathFactory,
                                         theXPath);

                theXPathProcessor.initXPath(*theXPath,
                                            theXPathConstructionContext,
                                            theXPathString,
                                            thePrefixResolver);

                bool    fDump = false;

                if (fDump == true)
                {
                    thePrintWriter.println();
                    thePrintWriter.println();
                    theXPath->getExpression().dumpOpCodeMap(thePrintWriter);
                    thePrintWriter.println();
                    theXPath->getExpression().dumpTokenQueue(thePrintWriter);
                    thePrintWriter.println();
                    thePrintWriter.println();
                }

                const XObjectPtr theResult =
                    theXPath->execute(theContextNode, thePrefixResolver, theContextNodeList, theExecutionContext);

                try
                {
                    assert(theResult.null() == false);

                    const NodeRefListBase&  theResultList =
                        theResult->nodeset();

                    const unsigned int  theLength = theResultList.getLength();

                    if (theLength == 0)
                    {
                        thePrintWriter.println("<out/>");
                    }
                    else
                    {
                        thePrintWriter.print("<out>");

                        for (unsigned int i = 0; i < theLength; i++)
                        {
                            thePrintWriter.print(theResultList.item(i)->getNodeName());
                            thePrintWriter.print(" ");
                        }

                        thePrintWriter.println("</out>");
                    }
                }
                catch(...)
                {
                    thePrintWriter.print("Execution of XPath ");
                    thePrintWriter.print(theXPathString);
                    thePrintWriter.println(" failed!");
                }
            }
        }
    }

    theLiaison.reset();

    return fError;
}
bool
TestPredicateResult(
            XPathProcessor&         theXPathProcessor,
            XPathEnvSupport&        theXPathEnvSupport,
            DOMSupport&             theDOMSupport,
            XMLParserLiaison&       theLiaison,
            XPathFactory&           theXPathFactory,
            const XalanDOMString&   theXMLFileURL,
            const XalanDOMString&   theXSLFileURL,
            PrintWriter&            thePrintWriter,
            XPathExecutionContext&  theExecutionContext)
{
    bool                    fError = false;

    XalanDocument* const    theXMLDocument =
                ParseXML(theLiaison,
                         theXMLFileURL);

    MemoryManagerType&      theMemoryManager =
        theExecutionContext.getMemoryManager();

    if (theXMLDocument != 0)
    {
        XalanDOMString      theContextNodeMatchPattern(theMemoryManager);
        XalanDOMString      theXPathString(theMemoryManager);

        if (GetXSLInput(theLiaison,
                        theXSLFileURL,
                        theContextNodeMatchPattern,
                        theXPathString,
                        theMemoryManager) == true)
        {
            XalanNode* const    theContextNode =
                FindContextNode(theXPathProcessor,
                                theXPathEnvSupport,
                                theDOMSupport,
                                theXPathFactory,
                                theXMLDocument,
                                theContextNodeMatchPattern,
                                thePrintWriter,
                                theExecutionContext);

            if (theContextNode != 0)
            {
                XalanElement* const             theNamespaceContext = 0;
                ElementPrefixResolverProxy      thePrefixResolver(theNamespaceContext, theXPathEnvSupport, theDOMSupport);
                NodeRefList                     theContextNodeList(theMemoryManager);

                XPath* const    theXPath1 = theXPathFactory.create();

                XPathConstructionContextDefault     theXPathConstructionContext(theMemoryManager);

                XPathGuard  theGuard1(theXPathFactory,
                                      theXPath1);

                XalanDOMString  theResult(theMemoryManager);

                theXPathProcessor.initXPath(*theXPath1,
                                            theXPathConstructionContext,
                                            TranscodeFromLocalCodePage("following-sibling::*", theResult),
                                            thePrefixResolver);

                XPath* const    theXPath2 = theXPathFactory.create();

                XPathGuard  theGuard2(theXPathFactory,
                                      theXPath2);

                theXPathProcessor.initXPath(*theXPath2,
                                            theXPathConstructionContext,
                                            TranscodeFromLocalCodePage("descendant::*", theResult),
                                            thePrefixResolver);

                bool    fDump = false;

                if (fDump == true)
                {
                    thePrintWriter.println();
                    thePrintWriter.println();
                    theXPath1->getExpression().dumpOpCodeMap(thePrintWriter);
                    thePrintWriter.println();
                    theXPath1->getExpression().dumpTokenQueue(thePrintWriter);
                    thePrintWriter.println();
                    thePrintWriter.println();
                    theXPath2->getExpression().dumpOpCodeMap(thePrintWriter);
                    thePrintWriter.println();
                    theXPath2->getExpression().dumpTokenQueue(thePrintWriter);
                    thePrintWriter.println();
                    thePrintWriter.println();
                }

                XalanNode*  theContextNode = theXMLDocument->getFirstChild()->getFirstChild();

                for( ; theContextNode != 0; theContextNode = theContextNode->getNextSibling())
                {
                    if (theContextNode->getNodeType() != XalanNode::ELEMENT_NODE)
                    {
                        continue;
                    }

                    const XObjectPtr theResult1 =
                            theXPath1->execute(theExecutionContext);

                    try
                    {
                        assert(theResult1.null() == false);

                        const NodeRefListBase&  theResultList =
                                theResult1->nodeset();

                        const unsigned int  theLength = theResultList.getLength();

                        thePrintWriter.print("theResult1->str() == \"");
                        thePrintWriter.print(theResult1->str());
                        thePrintWriter.print("\"");
                        thePrintWriter.println();

                        if (theLength > 0)
                        {
                            for (unsigned int i = 0; i < theLength; i++)
                            {
                                thePrintWriter.print(theResultList.item(i)->getNodeName());
                                thePrintWriter.println();
                            }
                        }
                    }
                    catch(...)
                    {
                        thePrintWriter.print("Execution of XPath ");
                        thePrintWriter.print(theXPathString);
                        thePrintWriter.println(" failed!");
                    }

                    const XObjectPtr    theResult2 =
                            theXPath2->execute(theExecutionContext);

                    try
                    {
                        assert(theResult2.null() == false);

                        const NodeRefListBase&  theResultList =
                                theResult2->nodeset();

                        const int   theLength = theResultList.getLength();

                        thePrintWriter.print("theResult2->str() == \"");
                        thePrintWriter.print(theResult2->str());
                        thePrintWriter.print("\"");
                        thePrintWriter.println();

                        if (theLength > 0)
                        {
                            for (int i = 0; i < theLength; i++)
                            {
                                thePrintWriter.print(theResultList.item(i)->getNodeName());
                                thePrintWriter.println();
                            }
                        }
                    }
                    catch(...)
                    {
                        thePrintWriter.print("Execution of XPath ");
                        thePrintWriter.print(theXPathString);
                        thePrintWriter.println(" failed!");
                    }

                    if (theResult1->equals(*theResult2, theExecutionContext) == true)
                    {
                        thePrintWriter.print("theResult1 is equal to theResult2");
                        thePrintWriter.println();
                        thePrintWriter.print("theContextNode->getNodeName() == \"");
                        thePrintWriter.print(theContextNode->getNodeName());
                        thePrintWriter.print("\"  theContextNode->getNodeValue() == \"");
                        thePrintWriter.print(theContextNode->getNodeValue());
                        thePrintWriter.println("\"");
                    }
                }
            }
        }
    }

    return fError;
}
示例#21
0
XSECXPathNodeList * TXFMXPathFilter::evaluateSingleExpr(DSIGXPathFilterExpr *expr) {

	// Have a single expression that we wish to find the resultant nodeset
	// for

	XSECXPathNodeList addedNodes;
	setXPathNS(document, expr->mp_NSMap, addedNodes, mp_formatter, mp_nse);

	XPathProcessorImpl	xppi;					// The processor
	XercesParserLiaison xpl;
#if XALAN_VERSION_MAJOR == 1 && XALAN_VERSION_MINOR > 10
	XercesDOMSupport	xds(xpl);
#else
	XercesDOMSupport	xds;
#endif
	XPathEvaluator		xpe;
	XPathFactoryDefault xpf;
	XPathConstructionContextDefault xpcc;

	XalanDocument		* xd;
	XalanNode			* contextNode;

	// Xalan can throw exceptions in all functions, so do one broad catch point.

	try {
	
		// Map to Xalan
		xd = xpl.createDocument(document);

		// For performing mapping
		XercesDocumentWrapper *xdw = xpl.mapDocumentToWrapper(xd);
		XercesWrapperNavigator xwn(xdw);

		// Map the "here" node

		XalanNode * hereNode = NULL;

		hereNode = xwn.mapNode(expr->mp_xpathFilterNode);

		if (hereNode == NULL) {

			hereNode = findHereNodeFromXalan(&xwn, xd, expr->mp_exprTextNode);

			if (hereNode == NULL) {

				throw XSECException(XSECException::XPathFilterError,
				   "Unable to find here node in Xalan Wrapper map");
			}

		}

		// Now work out what we have to set up in the new processing

		XalanDOMString cd;		// For XPath Filter, the root is always the context node

		cd = XalanDOMString("/");		// Root node

		// The context node is the "root" node
		contextNode =
			xpe.selectSingleNode(
			xds,
			xd,
			cd.c_str(),
			xd->getDocumentElement());

		XPathEnvSupportDefault xpesd;
		XObjectFactoryDefault			xof;
		XPathExecutionContextDefault	xpec(xpesd, xds, xof);

		ElementPrefixResolverProxy pr(xd->getDocumentElement(), xpesd, xds);

		// Work around the fact that the XPath implementation is designed for XSLT, so does
		// not allow here() as a NCName.

		// THIS IS A KLUDGE AND SHOULD BE DONE BETTER

		int offset = 0;
		safeBuffer k(KLUDGE_PREFIX);
		k.sbStrcatIn(":");

		// Map the expression into a local code page string (silly - should be XMLCh)
		safeBuffer exprSB;
		exprSB << (*mp_formatter << expr->m_expr.rawXMLChBuffer());

		offset = exprSB.sbStrstr("here()");

		while (offset >= 0) {

			if (offset == 0 || offset == 1 || 
				(!(exprSB[offset - 1] == ':' && exprSB[offset - 2] != ':') &&
				separator(exprSB[offset - 1]))) {

				exprSB.sbStrinsIn(k.rawCharBuffer(), offset);

			}

			offset = exprSB.sbOffsetStrstr("here()", offset + 11);

		}

		// Install the External function in the Environment handler

		if (hereNode != NULL) {

			xpesd.installExternalFunctionLocal(XalanDOMString(URI_ID_DSIG), XalanDOMString("here"), DSIGXPathHere(hereNode));

		}

		XPath * xp = xpf.create();

		XalanDOMString Xexpr((char *) exprSB.rawBuffer());
		xppi.initXPath(*xp, xpcc, Xexpr, pr);
		
		// Now resolve

		XObjectPtr xObj = xp->execute(contextNode, pr, xpec);

		// Now map to a list that others can use (naieve list at this time)

		const NodeRefListBase&	lst = xObj->nodeset();
		
		int size = (int) lst.getLength();
		const DOMNode *item;
		
		XSECXPathNodeList * ret;
		XSECnew(ret, XSECXPathNodeList);
		Janitor<XSECXPathNodeList> j_ret(ret);

		for (int i = 0; i < size; ++ i) {

			if (lst.item(i) == xd)
				ret->addNode(document);
			else {
				item = xwn.mapNode(lst.item(i));
				ret->addNode(item);
			}
		}

		xpesd.uninstallExternalFunctionGlobal(XalanDOMString(URI_ID_DSIG), XalanDOMString("here"));

		clearXPathNS(document, addedNodes, mp_formatter, mp_nse);

		j_ret.release();
		return ret;

	}

	catch (XSLException &e) {

		safeBuffer msg;

		// Whatever happens - fix any changes to the original document
		clearXPathNS(document, addedNodes, mp_formatter, mp_nse);
	
		// Collate the exception message into an XSEC message.		
		msg.sbTranscodeIn("Xalan Exception : ");
#if defined (XSEC_XSLEXCEPTION_RETURNS_DOMSTRING)
		msg.sbXMLChCat(e.getType().c_str());
#else
		msg.sbXMLChCat(e.getType());
#endif
		msg.sbXMLChCat(" caught.  Message : ");
		msg.sbXMLChCat(e.getMessage().c_str());

		throw XSECException(XSECException::XPathFilterError,
			msg.rawXMLChBuffer());

	}

	catch (...) {
		clearXPathNS(document, addedNodes, mp_formatter, mp_nse);
		throw;
	}

	return NULL;
}
示例#22
0
void TXFMXPath::evaluateExpr(DOMNode *h, safeBuffer inexpr) {

	// Temporarily add any necessary name spaces into the document

	XSECXPathNodeList addedNodes;
	setXPathNS(document, XPathAtts, addedNodes, formatter, mp_nse);

	XPathProcessorImpl	xppi;					// The processor
	XercesParserLiaison xpl;
#if XALAN_VERSION_MAJOR == 1 && XALAN_VERSION_MINOR > 10
	XercesDOMSupport	xds(xpl);
#else
	XercesDOMSupport	xds;
#endif
	XPathEvaluator		xpe;
	XPathFactoryDefault xpf;
	XPathConstructionContextDefault xpcc;

	XalanDocument		* xd;
	XalanNode			* contextNode;

	// Xalan can throw exceptions in all functions, so do one broad catch point.

	try {
	
		// Map to Xalan
		xd = xpl.createDocument(document);

		// For performing mapping
		XercesDocumentWrapper *xdw = xpl.mapDocumentToWrapper(xd);
		XercesWrapperNavigator xwn(xdw);

		// Map the "here" node - but only if part of current document

		XalanNode * hereNode = NULL;

		if (h->getOwnerDocument() == document) {
			
			hereNode = xwn.mapNode(h);

			if (hereNode == NULL) {

				hereNode = findHereNodeFromXalan(&xwn, xd, h);

				if (hereNode == NULL) {

					throw XSECException(XSECException::XPathError,
					   "Unable to find here node in Xalan Wrapper map");
				}

			}
		}

		// Now work out what we have to set up in the new processing

		TXFMBase::nodeType inputType = input->getNodeType();

		XalanDOMString cd;		// For the moment assume the root is the context

		const XalanDOMChar * cexpr;

		safeBuffer contextExpr;

		switch (inputType) {

		case DOM_NODE_DOCUMENT :
		case DOM_NODE_XPATH_NODESET :
			// do XPath over the whole document and, if the input was an 
			// XPath Nodeset, then later intersect the result with the input nodelist			
			cd = XalanDOMString("/");		// Root node
			cexpr = cd.c_str();

			// The context node is the "root" node
			contextNode =
				xpe.selectSingleNode(
				xds,
				xd,
				cexpr,
				xd->getDocumentElement());

			break;

		case DOM_NODE_DOCUMENT_FRAGMENT :
			{

				// Need to map the DOM_Node that we are given from the input to the appropriate XalanNode

				// Create the XPath expression to find the node

				if (input->getFragmentId() != NULL) {

					contextExpr.sbTranscodeIn("//descendant-or-self::node()[attribute::Id='");
					contextExpr.sbXMLChCat(input->getFragmentId());
					contextExpr.sbXMLChCat("']");

					// Map the node

					contextNode = 
						xpe.selectSingleNode(
						xds,
						xd,
						contextExpr.rawXMLChBuffer(), //XalanDOMString((char *) contextExpr.rawBuffer()).c_str(), 
						xd->getDocumentElement());


					if (contextNode == NULL) {
						// Last Ditch
						contextNode = xwn.mapNode(input->getFragmentNode());

					}

				}
				else
					contextNode = xwn.mapNode(input->getFragmentNode());

				if (contextNode == NULL) {

					// Something wrong
					throw XSECException(XSECException::XPathError, "Error mapping context node");

				}

				break;
			}

		default :

			throw XSECException(XSECException::XPathError);	// Should never get here

		}

		safeBuffer str;
		XPathEnvSupportDefault xpesd;
		XObjectFactoryDefault			xof;
		XPathExecutionContextDefault	xpec(xpesd, xds, xof);

		ElementPrefixResolverProxy pr(xd->getDocumentElement(), xpesd, xds);

		// Work around the fact that the XPath implementation is designed for XSLT, so does
		// not allow here() as a NCName.

		// THIS IS A KLUDGE AND SHOULD BE DONE BETTER

		int offset = 0;
		safeBuffer k(KLUDGE_PREFIX);
		k.sbStrcatIn(":");

		offset = inexpr.sbStrstr("here()");

		while (offset >= 0) {

			if (offset == 0 || offset == 1 || 
				(!(inexpr[offset - 1] == ':' && inexpr[offset - 2] != ':') &&
				separator(inexpr[offset - 1]))) {

				inexpr.sbStrinsIn(k.rawCharBuffer(), offset);

			}

			offset = inexpr.sbOffsetStrstr("here()", offset + 11);

		}

		// Install the External function in the Environment handler

		if (hereNode != NULL) {

			xpesd.installExternalFunctionLocal(XalanDOMString(URI_ID_DSIG), XalanDOMString("here"), DSIGXPathHere(hereNode));

		}

		str.sbStrcpyIn("(descendant-or-self::node() | descendant-or-self::node()/attribute::* | descendant-or-self::node()/namespace::*)[");
		str.sbStrcatIn(inexpr);
		str.sbStrcatIn("]");

		XPath * xp = xpf.create();

		XalanDOMString Xexpr((char *) str.rawBuffer());
		xppi.initXPath(*xp, xpcc, Xexpr, pr);
		
		// Now resolve

		XObjectPtr xObj = xp->execute(contextNode, pr, xpec);

		// Now map to a list that others can use (naieve list at this time)

		const NodeRefListBase&	lst = xObj->nodeset();
		
		int size = (int) lst.getLength();
		const DOMNode *item;
		
		for (int i = 0; i < size; ++ i) {

			if (lst.item(i) == xd)
				m_XPathMap.addNode(document);
			else {
				item = xwn.mapNode(lst.item(i));
				m_XPathMap.addNode(item);
			}
		}

		if (inputType == DOM_NODE_XPATH_NODESET) {
			//the input list was a XPATH nodeset, so we must intersect the 
			// results of the XPath processing done above with the input nodeset
			m_XPathMap.intersect(input->getXPathNodeList());
		}
	}

	catch (XSLException &e) {

		safeBuffer msg;

		// Whatever happens - fix any changes to the original document
		clearXPathNS(document, addedNodes, formatter, mp_nse);
	
		// Collate the exception message into an XSEC message.		
		msg.sbTranscodeIn("Xalan Exception : ");
#if defined (XSEC_XSLEXCEPTION_RETURNS_DOMSTRING)
		msg.sbXMLChCat(e.getType().c_str());
#else
		msg.sbXMLChCat(e.getType());
#endif
		msg.sbXMLChCat(" caught.  Message : ");
		msg.sbXMLChCat(e.getMessage().c_str());

		throw XSECException(XSECException::XPathError,
			msg.rawXMLChBuffer());
	}
	
	clearXPathNS(document, addedNodes, formatter, mp_nse);

}
const XObjectPtr
VariablesStack::findXObject(
            const XalanQName&               name,
            StylesheetExecutionContext&     executionContext,
            bool                            fIsParam,
            bool                            fSearchGlobalSpace,
            bool&                           fNameFound)
{
    typedef VariableStackStackType::size_type   size_type;

    // findEntry() returns an index into the stack.  We should
    // _never_ take the address of anything in the stack, since
    // the address could change at unexpected times.
    const size_type     theEntryIndex =
        findEntry(name, fIsParam, fSearchGlobalSpace);

    if (theEntryIndex == m_stack.size())
    {
        fNameFound = false;

        return XObjectPtr();
    }
    else
    {
        assert(theEntryIndex < m_stack.size());

        fNameFound = true;

        assert(m_stack[theEntryIndex].getType() == StackEntry::eVariable ||
               m_stack[theEntryIndex].getType() == StackEntry::eParam ||
               m_stack[theEntryIndex].getType() == StackEntry::eActiveParam);

        const XObjectPtr&   theValue = m_stack[theEntryIndex].getValue();

        if (theValue.null() == false)
        {
            return theValue;
        }
        else
        {
            const ElemVariable* const   var = m_stack[theEntryIndex].getVariable();

            XObjectPtr                  theNewValue;

            if (var != 0)
            {
                XalanNode* const    doc = executionContext.getRootDocument();
                assert(doc != 0);

                XALAN_USING_STD(find)

                // See if the ElemVariable instance is already being evaluated...
                if (find(m_guardStack.begin(), m_guardStack.end(), var) != m_guardStack.end())
                {
                    const StylesheetExecutionContext::GetCachedString   theGuard(executionContext);

                    executionContext.error(
                        XalanMessageLoader::getMessage(
                            theGuard.get(),
                            XalanMessages::CircularVariableDefWasDetected),
                        doc,
                        var->getLocator());
                }

                m_guardStack.push_back(var);

#if !defined(XALAN_RECURSIVE_STYLESHEET_EXECUTION)
                executionContext.pushContextMarker();
#else
                // We need to set up a stack frame for the variable's execution...
                typedef StylesheetExecutionContext::PushAndPopContextMarker PushAndPopContextMarker;

                const PushAndPopContextMarker   theContextMarkerPushPop(executionContext);
#endif

                theNewValue = var->getValue(executionContext, doc);
                assert(theNewValue.null() == false);

#if !defined(XALAN_RECURSIVE_STYLESHEET_EXECUTION)
                executionContext.popContextMarker();
#endif

                assert(m_guardStack.empty() == false);

                m_guardStack.pop_back();

                m_stack[theEntryIndex].setValue(theNewValue);
                m_stack[theEntryIndex].activate();
            }

            return theNewValue;
        }
    }
示例#24
0
XObjectPtr
FunctionSubstring::execute(
			XPathExecutionContext&	executionContext,
			XalanNode*				/* context */,
			const XObjectPtr		arg1,
			const XObjectPtr		arg2,
			const XObjectPtr		arg3,
			const LocatorType*		/* locator */) const
{
	assert(arg1.null() == false && arg2.null() == false);	

	const XalanDOMString&				theSourceString = arg1->str();
	const XalanDOMString::size_type		theSourceStringLength = length(theSourceString);

	if (theSourceStringLength == 0)
	{
		return createEmptyString(executionContext);
	}
	else
	{
		// Get the value of the second argument...
		const double	theSecondArgValue =
			DoubleSupport::round(arg2->num());

		// XPath indexes from 1, so this is the first XPath index....
		const XalanDOMString::size_type		theStartIndex = getStartIndex(theSecondArgValue, theSourceStringLength);

		if (theStartIndex >= theSourceStringLength)
		{
			return createEmptyString(executionContext);
		}
		else
		{
			const double	theTotal =
				getTotal(theSourceStringLength, theSecondArgValue, arg3);

			if (DoubleSupport::isNaN(theSecondArgValue) == true ||
				DoubleSupport::isNaN(theTotal) == true ||
				DoubleSupport::isNegativeInfinity(theTotal) == true ||
				theTotal == 0.0 ||
				theTotal < double(theStartIndex))
			{
				return createEmptyString(executionContext);
			}
			else
			{
				const XalanDOMString::size_type		theSubstringLength =
					getSubstringLength(
						theSourceStringLength,
						theStartIndex,
						theTotal);

				XPathExecutionContext::GetAndReleaseCachedString	theResult(executionContext);

				XalanDOMString&		theString = theResult.get();

				assign(
						theString,
						toCharArray(theSourceString) + theStartIndex,
						theSubstringLength);

				return executionContext.getXObjectFactory().createString(theResult);
			}
		}
	}
}
XObjectPtr
FunctionSubstringAfter::execute(
            XPathExecutionContext&  executionContext,
            XalanNode*              /* context */,
            const XObjectPtr        arg1,
            const XObjectPtr        arg2,
            const LocatorType*      /* locator */) const
{
    assert(arg1.null() == false && arg2.null() == false);

    const XalanDOMString&               theFirstString = arg1->str();

    const XalanDOMString::size_type     theFirstStringLength = length(theFirstString);

    if (theFirstStringLength == 0)
    {
        return createEmptyString(executionContext);
    }
    else
    {
        const XalanDOMString&   theSecondString = arg2->str();

        const XalanDOMString::size_type     theSecondStringLength = length(theSecondString);

        if (theSecondStringLength == 0)
        {
            return arg1;
        }
        else
        {
            const XalanDOMString::size_type     theIndex = indexOf(theFirstString,
                                                       theSecondString);

            if (theIndex == theFirstStringLength)
            {
                return createEmptyString(executionContext);
            }
            else
            {
                const XalanDOMString::size_type     theSecondStringLength = length(theSecondString);

                // Find the first character, which will be the offset of the index of the
                // beginning of the second string, plus the length of the second string.
                const XalanDOMChar* const   theFirstCharacter =
                    toCharArray(theFirstString) + theIndex + theSecondStringLength;

                // The remaining length is just the opposite -- the length of the string,
                // minus the index, minus the length of the second string.
                const XalanDOMString::size_type     theSubstringLength =
                    theFirstStringLength  - theIndex - theSecondStringLength;

                XPathExecutionContext::GetAndReleaseCachedString    theResult(executionContext);

                XalanDOMString&     theString = theResult.get();

                assign(
                        theString,
                        theFirstCharacter,
                        theSubstringLength);

                return executionContext.getXObjectFactory().createString(theResult);
            }
        }
    }
}