cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robin Green" <gree...@hotmail.com>
Subject Re: XSP adding XML java.
Date Wed, 03 May 2000 19:39:16 GMT
Kees Jongenburger <keesj@netlinq.nl>  wrote:
>i am currently writing a poll class witch should be used as part of an 
>XSPlib
>to be incorporated with different pages. Now the poll class should return 
>part
>of an XML document something like
>this:
><poll>
>	<question>
>	    <title>Should Cocoon have default polls?</title>
>	    <answers>
>		    <answer name="Yes Yes Yes!!!" value="yes"/>
>		    <answer name="No No No!!!" value="yes"/>
>	    </answers>
>	</question>
></poll>
>
>my xsl(from the lib) looks like this:
><xsl:template match="netlinq:poll">
>         <xsl:copy>
>              <xsp:expr>forum.getForum()</xsp:expr>
>         </xsl:copy>
></xsl:template>
>
>
>Now in java if i return a String the < and > tags are transformed so that
>the exact text is displayed . If i return an XObject results are better
>(only the #text is returned but the tags are omited)
>
>what should the aproch be?
>i realy whant to be able to use "Pure" java to create document fragments 
>witch
>wil be processed by the xslt
>

No probs. I've been doing that myself for a web discussion board package. 
It's easy. Just build a DOM Element and don't use <xsp:expr> to insert it, 
but instead use this code, or something like it:

<xsl:template match="netlinq:poll">
   <xsl:copy>
     <xsp:logic>
       xspCurrentNode.appendChild (forum.getForum());
     </xsp:logic>
   </xsl:copy>
</xsl:template>


I have made a little tag to encapsulate this (when using XSP), called 
<add-node>

  <xsl:template match="add-node">
    <xsp:logic>
      xspCurrentNode.appendChild(
        <xsl:apply-templates/>
      );
    </xsp:logic>

so you can then just say (in an XSP page, not in a stylesheet)

  <add-node>object.toXML() // NOTE: no semicolon
  </add-node>

but that's just for convenience, you don't need to make an abstract tag for 
it.



--
Robin

270+ Open Source Java links! 
http://directory.mozilla.org/Computers/Programming/Languages/Java/Open_Source/

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


Mime
View raw message