You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Juergen Hermann <jh...@webde-ag.de> on 2000/06/06 14:05:49 UTC

[XALAN-C] Converting a RTF to a node-set

Environment: Linux (Suse 6.3), Xerces & Xalan from CVS (2000-06-05).

[Yes, the current CVS does compile on Linux. Thanks, David. :) ]


Given the following stylesheet (the input document is simply "<root/>"):

---8<------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1" ?> 
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:cops="http://www.cinetic.de/2000/COPS">
  <xsl:output method="xml"/>

  <xsl:variable name="greeting">abc<h1>Hello, World!</h1>def</xsl:variable>

  <xsl:template match="root">
    Hello, World!
    <xsl:for-each select="cops:node-set($greeting)">*<xsl:copy-of select="."/>*
    </xsl:for-each>
    <xsl:for-each select="cops:range(1,11,2)">#<xsl:value-of select="."/># </xsl:for-each>
  </xsl:template>
                
</xsl:stylesheet>
---8<------------------------------------------------------------

... and this code for the cops:node-set extension:

---8<------------------------------------------------------------
#define VARIANT 1

    if (VARIANT != 1 && argVec[0]->getType() == XObject::eTypeResultTreeFrag)
    {
        MutableNodeRefList clone(executionContext.createMutableNodeRefList());
        const ResultTreeFragBase& rtree = argVec[0]->rtree();

#if VARIANT == 2
        clone.addNodesInDocOrder(*rtree.getChildNodes());
#else
        const XalanNodeList* childnodes = rtree.getChildNodes();
        unsigned int nChilds = childnodes->getLength();
        STRACE(TRACE_DEBUG, "XSLT", "    RTF has " << nChilds << " child nodes.");
        STRACE(TRACE_DEBUG, "XSLT", "    context = " << context);
        STRACE(TRACE_DEBUG, "XSLT", "    context.owner = " << context->getOwnerDocument());

        for (unsigned int idx = 0; idx < nChilds; ++idx)
        {
            XalanNode* srcnode = childnodes->item(idx);
            STRACE(TRACE_DEBUG, "XSLT", "    clone child"
                    << ", name = '" << srcnode->getNodeName().transcode() << "'"
                    << ", value = '" << srcnode->getNodeValue().transcode() << "'");

#if VARIANT == 3
            XalanNode* newnode = context->getOwnerDocument()->importNode(srcnode, false);
            STRACE(TRACE_DEBUG, "XSLT", "    new node = " << newnode);
            clone.addNode(newnode);
#else
            clone.addNode(srcnode);
#endif
        }
#endif

        return executionContext.getXObjectFactory().createNodeSet(clone);
    } else {
        return executionContext.getXObjectFactory().createNodeSet(argVec[0]->nodeset());
    }
---8<------------------------------------------------------------

I get this output for VARIANT == 1:

    Hello, World!
    *abc*
    #1# #3# #5# #7# #9# #11#

As you can see, it returns the first node only for this most naive variant.

VARIANT == 2:

2000-06-06 12:43:06.000  DEBUG (XSLT) in XMLStylesheet.cpp[176]: Transforming...
2000-06-06 12:43:06.000  ERROR (XSLT) in XMLStylesheet.cpp[616]: XSLException XSLException Child does not have parent!

VARIANT == 3:

2000-06-06 12:45:59.000  DEBUG (XSLT) in XMLStylesheet.cpp[176]: Transforming...
2000-06-06 12:45:59.000  DEBUG (XSLT) in XMLStylesheet.cpp[310]:     RTF has 3 child nodes.
2000-06-06 12:45:59.000  DEBUG (XSLT) in XMLStylesheet.cpp[311]:     context = 0x8173318
2000-06-06 12:45:59.000  DEBUG (XSLT) in XMLStylesheet.cpp[312]:     context.owner = 0x816e7a0
2000-06-06 12:45:59.000  DEBUG (XSLT) in XMLStylesheet.cpp[319]:     clone child, name = '#text', value = 'abc'

... and then dumps core.

VARIANT == 4:

2000-06-06 12:48:00.000  DEBUG (XSLT) in XMLStylesheet.cpp[176]: Transforming...
2000-06-06 12:48:00.000  DEBUG (XSLT) in XMLStylesheet.cpp[310]:     RTF has 3 child nodes.
2000-06-06 12:48:00.000  DEBUG (XSLT) in XMLStylesheet.cpp[311]:     context = 0x8173298
2000-06-06 12:48:00.000  DEBUG (XSLT) in XMLStylesheet.cpp[312]:     context.owner = 0x816e720
2000-06-06 12:48:00.000  DEBUG (XSLT) in XMLStylesheet.cpp[319]:     clone child, name = '#text', value = 'abc'
2000-06-06 12:48:00.000  DEBUG (XSLT) in XMLStylesheet.cpp[319]:     clone child, name = 'h1', value = ''
2000-06-06 12:48:00.000  DEBUG (XSLT) in XMLStylesheet.cpp[319]:     clone child, name = '#text', value = 'def'
pypp: DOMSupport/DOMServices.cpp:367: static class XalanNode * DOMServices::getParentOfNode(const class XalanNode &): Assertion »rootElem != 0« failed.






Ciao, Jürgen

--
Jürgen Hermann (jhe@webde-ag.de)
WEB.DE AG, Amalienbadstr.41, D-76227 Karlsruhe
Tel.: 0721/94329-0, Fax: 0721/94329-22