You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Ulf Heyder <uh...@gmx.de> on 2004/07/16 09:18:34 UTC

Xalan - Passing node as parameter to an external C++ function

Hi again,

I still don't have it:

How can I in Xalan 1.8.0 pass an xml node to an external C++ function and
get the whole node xml-chars in that function?

xmlInput:
---------
<?xml...>
<Main>
...
 <Foo>
  <SubFoo>
   <Value>
    blah
   </Value>
  </SubFoo>
 </Foo>
...
</Main>

xslt:
---------
...
 <xsl:template match="/">
 ...
  <xsl:variable name="foo" select="//Foo[1]"/>
  <xsl:variable name="result" select="ext:doIt($foo/SubFoo)"/>
 ...

C++:
---------
XObjectPtr FunctionDoIt::execute(XPathExecutionContext& executionContext,
XalanNode* context,
            const XObjectPtr arg1, const LocatorType* locator) const
{
...
 std::vector<char> charVek = arg1->str().transcode();
 char* chars = &charVek[0];

 doSthWith(chars);
...
 return executionContext.getXObjectFactory().createBoolean(result);
}

When I use this code the "chars" only contains all the element values but
not the tags themselves:
chars =>"


    blah


         "

instead of

chars =>
 "<Foo>
  <SubFoo>
   <Value>
    blah
   </Value>
  </SubFoo>
 <Foo>"


Thanks, Ulf


Looking for advice on using xalan to process xml

Posted by sk ask <ar...@yahoo.com>.
Hi, I would like to know a good way to process this
kind of proposed xml

<?xml version="1.0" ?>
<nodes>
<node path="item1[/info/@nameRef]:item2[/info2/@desc]>
</node>
<node path="itemFromRefAbove[/info2/@name2ref]/>
</nodes>

I would like to parse the content of the path
attribute
via an external c function. This content is used to
find the item1 element in another xml file. Once, it
is found need to evaluate the expression in [] on
this node/element. The result of evaluating the first
path could yield an element on which the next path
expression could be used and so on.

Any opinions on this would be appreciated.



Re: Xalan - Passing node as parameter to an external C++ function

Posted by da...@us.ibm.com.
> Hi again,
>
> I still don't have it:
>
> How can I in Xalan 1.8.0 pass an xml node to an external C++ function and
> get the whole node xml-chars in that function?

The input to an XSLT processor is a tree of nodes, not XML markup.

> When I use this code the "chars" only contains all the element values but
> not the tags themselves:
> chars =>"
>
>
>     blah
>
>
>          "

"Tags" are markup, not nodes, and there is no markup.

> chars =>
>  "<Foo>
>   <SubFoo>
>    <Value>
>     blah
>    </Value>
>   </SubFoo>
>  <Foo>"

You could re-serialize the source tree from that point, but that seems
really inefficient.  If you need markup for your processing, why aren't you
using some text-processing program, instead of XSLT?  The other option
would be to re-write your extension function to work with the source tree
(nodes), rather than markup.  Maybe if you described what your function
will do with this markup, we could come up with some better answers.

Dave