[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Controlling the flow of a program


Subject: [xsl] Controlling the flow of a program
From: Fadi Qutaishat <fadi_taher2000@xxxxxxxxx>
Date: Wed, 29 Jun 2005 06:34:14 -0700 (PDT)

Hi all,

First of all I apologize for putting much code in this
post, but I did not know how to explain my problem
without doing so.

My problem is like the following: 

At a particular point I merge XML tags that are
retrieved from MySQL database with a document
transformed using XSLT file. So the result would be
something like:

  <?xml version="1.0" encoding="ISO-8859-1" ?>
<user>
   <user xmlns:sql="http://apache.org/cocoon/SQL/2.0">
      <name>cocoon</name>
      <password>wizard</password>   
     ...
     ...

      <chunk_name1>general explanations</chunk_name1>

      <chunk_name1_knowledge>0</chunk_name1_knowledge>

      <chunk_name2>symptoms general</chunk_name2>

      <chunk_name2_knowledge>0</chunk_name2_knowledge>
    ...
    ...
   </user>

   <page>
      <chunk name="general explanations" type="text"
simplicity="tip" priority="1">
         <symbolizedname>chunk_name1</symbolizedname>

        
<symbolizedknowledge>chunk_name1_knowledge</symbolizedknowledge>

         <requiredknowledge>0</requiredknowledge>

         <requiredfor>
            <item>symptoms general</item>

            <item>treatment general</item>
         </requiredfor>

         <reqsymbolizedname>
            <item>chunk_name2</item>

            <item>chunk_name5</item>
         </reqsymbolizedname>

         <reqsymbolizedknowledge>
            <item>chunk_name2_knowledge</item>

            <item>chunk_name5_knowledge</item>
         </reqsymbolizedknowledge>

         <sections>
            <section>
               <h1>General explanations</h1>

               <p>This is a general explanations 
               <B>"tip"</B>

               paragraph</p>
            </section>
         </sections>

         <relatedpipeline>
            <knowledgebased-url>
               <pipeline id="symptoms
general">continue(2)</pipeline>

               <pipeline id="treatment
general">continue(5)</pipeline>
            </knowledgebased-url>

            <static-knowledgebased-url>
               <pipeline
info_simplicity="factsheet">other(1)</pipeline>

               <pipeline
info_simplicity="advanced">other(1)</pipeline>
            </static-knowledgebased-url>

            <non-knowledgebased-url>
               <pipeline>support groups</pipeline>
            </non-knowledgebased-url>
         </relatedpipeline>
      </chunk>
   
    <chunk name="symptoms general" type="text"
simplicity="tip" priority="2">
    
  <symbolizedname>chunk_name2</symbolizedname> 
  
 
<symbolizedknowledge>chunk_name2_knowledge</symbolizedknowledge>

  
  <requiredknowledge>1</requiredknowledge> 
  ...
  ...

<!-- The rest of all chunks go here, they have like
the above structure -->
   </page>
</user>
 
Then I use a XSLT file to do a comparison between the
required knowledge of the chunk and the users
knowledge about that chunk, In case of any match, this
chunk should be copied. This copied chunk contains
tags named <reqsymbolizedknowledge> used for updating
values of other chunks  and that is accomplished using
the following XSLT file:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:param name="id" />

   <xsl:param name="name" />
...
...
 <!--
########################################################
                       Main template 
########################################################
-->
   <xsl:template match="page">
      <page>
         <xsl:apply-templates select="/"
mode="content">
            <xsl:sort select="@priority"
data-type="number" />
         </xsl:apply-templates>

         <xsl:apply-templates select="/" mode="links"
/>

      </page>
   </xsl:template>


<!--
########################################################
                       Content template 
########################################################
-->
   <xsl:template match="chunk" mode="content">
      <xsl:variable name="symbolizedknowledge">
         <xsl:value-of select="symbolizedknowledge" />
      </xsl:variable>

      <xsl:variable name="name_chunk">
         <xsl:value-of select="@name" />
      </xsl:variable>

      <xsl:variable name="reqsymbolizedknowledge1">
         <xsl:value-of
select="reqsymbolizedknowledge/item[1]" />
      </xsl:variable>

      <xsl:variable name="reqsymbolizedknowledge2">
         <xsl:value-of
select="reqsymbolizedknowledge/item[2]" />
      </xsl:variable>

      <xsl:choose>
         <xsl:when
test="number(requiredknowledge)=number(preceding::*[name()=$symbolizedknowledge])">
            <xsl:copy-of select="." />

         <xsl:if test="reqsymbolizedknowledge/ite[1]">

<!-- To ensure that item[1] is not empty, if it is
empty the update should not happen -->
               <execute-query
xmlns="http://apache.org/cocoon/SQL/2.0">
                  <query>update ms_concepts set 
                  <xsl:value-of
select="$reqsymbolizedknowledge1" /> =1 where id=
                  <xsl:value-of select="$id" />
                  </query>
               </execute-query>
            </xsl:if>

        <xsl:if test="reqsymbolizedknowledge/item[2]">
               <execute-query
xmlns="http://apache.org/cocoon/SQL/2.0">
                  <query>update ms_concepts set 
                  <xsl:value-of
select="$reqsymbolizedknowledge2" /> =1 where id=
                  <xsl:value-of select="$id" />
                  </query>
               </execute-query>
            </xsl:if>
         </xsl:when>

         <xsl:otherwise>
<!-- do nothing for the time being -->
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
</xsl:stylesheet>

...
...

What happens now is that the comparison is done well
but I have problem with the update in that all of the
items found in the <reqsymbolizedknowledge> tag are
accessed for all chunks at once. Therefore, all of the
chunks values become "1".

What I need to do is updating the values according to
the items in the <reqsymbolizedknowledge> tag for only
the current chunk that is being copied.     
   
Is there away to tell the processor to only process
the current chunk being copied not all of the chunks?

I am using Apahce cocoon 2.1.6

I do not know I have made myself clear enough, please
feel free to ask if you need any further information.

Kind regards,

Fadi 



		
____________________________________________________ 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com


Current Thread
Keywords