This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Wanted: Extension functions using DOM interfaces


(Juergen Hermann):

> I hope you can grok it, even with the German comments. :)

Probably, but for anyone who can't, here's Juergen's code with
comments and output string translated:

=============================================================
This is "saxon:range" (plus a 3rd parameter, "step"):

XObject* cops_range(
XPathExecutionContext& executionContext,
const XalanDOMString& theNamespace,
const XalanDOMString& functionName,
XalanNode* context,
const XPathEnvSupport::XObjectArgVectorType& argVec)
{
    // Check the number of arguments
    if (argVec.size() < 2 || 3 < argVec.size())
    {
        executionContext.error("cops:range expects two or three
arguments!", context);

        // According to docs, this function MAY throw an
exception
        // To be on the safe side, we provide a return value
        return
executionContext.getXObjectFactory().createNull();
    }

    // Fetch the arguments
    long from =3D long(floor(argVec[0]->num() + .5));
    long to   =3D long(floor(argVec[1]->num() + .5));
    long step =3D 1;
    if (argVec.size() >=3D 3) step =3D
long(floor(argVec[2]->num() + .5)=
);
    if (!step) step =3D 1;

    // Create and populate results list
    MutableNodeRefList
result(executionContext.createMutableNodeRefList(=
));
    for (long num =3D from; num <=3D to; num +=3D step)
    {
        XalanText* numNode =3D
context->getOwnerDocument()->createTextNo=
de(strNum(num).c_str());
        result.addNode(static_cast<XalanNode*>(numNode));
    }

    return
executionContext.getXObjectFactory().createNodeSet(result);
}

================================================================
===
Michael Beddow
University of Leeds UK


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]