You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Andres Taborda <at...@saludcolombiaeps.com.co> on 2004/05/15 15:35:38 UTC

example recursion tree

Some user can help me with an example
of recursion for display an svg tree with nodes....

for example:

            A
	 /   \	
	B     C
              / \
       ....   .....

My preocupation is howto capture and save position previous and next
nodes father and subnodes,etc.


I have the follow code but not know if is efficient.

//file xml
<?xml version="1.0"?>
<xsp:page xmlns:xsp="http://apache.org/xsp"
    xmlns:session="http://apache.org/xsp/session/2.0"
    xmlns:cinclude="http://apache.org/cocoon/include/1.0">
<estructura>
    <componente posicionX="250" posicionY="40">

       <descripcion>raiz</descripcion>
       <etiqueta>name</etiqueta>

       <contiene>
          <componente posicionX="350" posicionY="100">
             <descripcion>hijo1</descripcion>
             <etiqueta>name1</etiqueta>
          </componente>

          <componente posicionX="170" posicionY="100">
             <descripcion>hijo2</descripcion>
             <etiqueta>name2</etiqueta>
          </componente>
       </contiene>
    </componente>
</estructura>
</xsp:page>

//code xsl
<?xml version="1.0"?>

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="estructura">
<svg width="1000" height="1000">
<!-- definiciones para usar despues -->
<defs>
<filter id="blur1"><feGaussianBlur stdDeviation="3"/></filter>
<filter id="blur2"><feGaussianBlur stdDeviation="1"/></filter>
<filter id="dropShadow" filterUnits="userSpaceOnUse" x="0" y="0" 
width="500" height="500">
  <feOffset in="SourceAlpha" dx="5" dy="5" result="offset"/>
  <feGaussianBlur in="offset" stdDeviation="5" result="blur"/>
  <feMerge><feMergeNode in="blur"/><feMergeNode 
in="SourceGraphic"/></feMerge>
</filter>
</defs>
<!-- grafica -->
<g title="this is a tooltip">
<!-- definimos la plantilla area de trabajo -->
<rect x="2" y="2" width="600" height="600" fill="none" stroke="black" 
stroke-width="2"/>
<xsl:apply-templates/>
</g>
</svg>
</xsl:template>


<xsl:template match="componente">
<circle cx="{@posicionX}" cy="{@posicionY}" r="13" 
style="fill:red;stroke:black;stroke-width:3;filter:url(#dropShadow);"/>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="contiene">
<xsl:for-each select="componente">
<!--  <line x1="250" y1="53" x2="{@posicionX}" y2="{@posicionY}" 
stroke-width="2" stroke="#030959"/> -->
<circle cx="{@posicionX}" cy="{@posicionY}" r="13" 
style="fill:yellow;stroke:black;stroke-width:3;filter:url(#dropShadow);"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Bye, thanks very much


-- 
Cordialmente,

Andres Taborda
Departamento de Sistemas
http://www.saludcolombiaeps.com.co
email:ataborda@saludcolombiaeps.com.co
SaludColombia E.P.S. - Una Sola Familia
Calle 5C # 43-05 Tequendama
Telefono : 57 (002) 551 04 89 - 57 (002) 551 04 90 Ext 119
Cali - Colombia


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: example recursion tree

Posted by Lars Huttar <la...@sil.org>.
Hi,
I think your question has more to do with XSL than with Cocoon, but anyway
here's what I can tell you...

First, your xsp page really doesn't need to be an XSP page...
it's static, so you could just use an XML file. But maybe you know
that and you plan to make it dynamic later.

As for your XSL stylesheet, what you are doing works, but I'm
not sure what you want to do. It looks like you're rendering top-level
<componente> nodes in red and second-level <componente> nodes yellow;
further-down nodes will not be rendered. Is that what you intended?

> My preocupation is howto capture and save position previous and next
> nodes father and subnodes,etc.

Can you explain this more elaborately?

If you want to recursively draw all <componente> nodes at any depth,
you'll want something like this:

<xsl:template match="contiene">
	<xsl:apply-templates />
</xsl:template>

but that won't give you different colors for the different levels.
For that you may want something like:

<xsl:template match="componente">
  <xsl:variable name="depth" select="count(ancestor::componente)" />
  <xsl:variable name="color">
    <xsl:choose>
      <xsl:when test="$depth = 0">red</xsl:when>
      <xsl:when test="$depth = 1">yellow</xsl:when>
      <xsl:when test="$depth = 2">green</xsl:when>
		<!-- etc. -->
      <xsl:otherwise>blue</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <circle cx="{@posicionX}" cy="{@posicionY}" r="13" 
    style="fill:{$color};stroke:black;stroke-width:3;filter:url(#dropShadow);"/>
 <xsl:apply-templates/>
</xsl:template>
 
You will also want an empty template to "consume" any other elements.
If you don't, the default template will output their text contents
which may confuse the SVG processor.  E.g.
  <xsl:template match="*">
  </xsl:template>

Hope this helps.

(Disclaimer: I don't know anything about SVG, nor do I read Spanish...
I just offer this as somebody who knows some XSLT.)

Lars

> -----Original Message-----
> From: Andres Taborda [mailto:ataborda@saludcolombiaeps.com.co]
> Sent: Saturday, May 15, 2004 8:36 AM
> To: users@cocoon.apache.org
> Subject: example recursion tree
> 
> 
> Some user can help me with an example
> of recursion for display an svg tree with nodes....
> 
> for example:
> 
>             A
> 	 /   \	
> 	B     C
>               / \
>        ....   .....
> 
> My preocupation is howto capture and save position previous and next
> nodes father and subnodes,etc.
> 
> 
> I have the follow code but not know if is efficient.
> 
> //file xml
> <?xml version="1.0"?>
> <xsp:page xmlns:xsp="http://apache.org/xsp"
>     xmlns:session="http://apache.org/xsp/session/2.0"
>     xmlns:cinclude="http://apache.org/cocoon/include/1.0">
> <estructura>
>     <componente posicionX="250" posicionY="40">
> 
>        <descripcion>raiz</descripcion>
>        <etiqueta>name</etiqueta>
> 
>        <contiene>
>           <componente posicionX="350" posicionY="100">
>              <descripcion>hijo1</descripcion>
>              <etiqueta>name1</etiqueta>
>           </componente>
> 
>           <componente posicionX="170" posicionY="100">
>              <descripcion>hijo2</descripcion>
>              <etiqueta>name2</etiqueta>
>           </componente>
>        </contiene>
>     </componente>
> </estructura>
> </xsp:page>
> 
> //code xsl
> <?xml version="1.0"?>
> 
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 
> <xsl:template match="estructura">
> <svg width="1000" height="1000">
> <!-- definiciones para usar despues -->
> <defs>
> <filter id="blur1"><feGaussianBlur stdDeviation="3"/></filter>
> <filter id="blur2"><feGaussianBlur stdDeviation="1"/></filter>
> <filter id="dropShadow" filterUnits="userSpaceOnUse" x="0" y="0" 
> width="500" height="500">
>   <feOffset in="SourceAlpha" dx="5" dy="5" result="offset"/>
>   <feGaussianBlur in="offset" stdDeviation="5" result="blur"/>
>   <feMerge><feMergeNode in="blur"/><feMergeNode 
> in="SourceGraphic"/></feMerge>
> </filter>
> </defs>
> <!-- grafica -->
> <g title="this is a tooltip">
> <!-- definimos la plantilla area de trabajo -->
> <rect x="2" y="2" width="600" height="600" fill="none" stroke="black" 
> stroke-width="2"/>
> <xsl:apply-templates/>
> </g>
> </svg>
> </xsl:template>
> 
> 
> <xsl:template match="componente">
> <circle cx="{@posicionX}" cy="{@posicionY}" r="13" 
> style="fill:red;stroke:black;stroke-width:3;filter:url(#dropSh
> adow);"/>
> <xsl:apply-templates/>
> </xsl:template>
> 
> <xsl:template match="contiene">
> <xsl:for-each select="componente">
> <!--  <line x1="250" y1="53" x2="{@posicionX}" y2="{@posicionY}" 
> stroke-width="2" stroke="#030959"/> -->
> <circle cx="{@posicionX}" cy="{@posicionY}" r="13" 
> style="fill:yellow;stroke:black;stroke-width:3;filter:url(#dro
> pShadow);"/>
> </xsl:for-each>
> </xsl:template>
> </xsl:stylesheet>
> 
> Bye, thanks very much
> 
> 
> -- 
> Cordialmente,
> 
> Andres Taborda
> Departamento de Sistemas
> http://www.saludcolombiaeps.com.co
> email:ataborda@saludcolombiaeps.com.co
> SaludColombia E.P.S. - Una Sola Familia
> Calle 5C # 43-05 Tequendama
> Telefono : 57 (002) 551 04 89 - 57 (002) 551 04 90 Ext 119
> Cali - Colombia
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org