xsl-list
[Top] [All Lists]

RE: [xsl] failed to find the right child node

2006-08-31 11:11:55

It seems likely that the number that you are  trying to calculate is
obtainable just from a simple xpath count and doesn't require a
recursive template, but I'm not sure as I don't follow your
description.

The example I gave is not very clear. It is possible <fast_load_stream>
doesn't have channel_object. So I have to recursively to check each
<fast_load_stream> to see whether it contains channel object. One
example is channel_objects spread on more than one networks. 

<streams>
  <legacy_stream name="stream1">
    <mpt_stream>
        <apg_stream>
          <fast_load_stream>
                <network_id>0</network_id>
                <objects>
                   <channel_object ref="CO1"/>
                   <channel_object ref="CO2"/>
                </objects>
          </fast_load_stream>
        </apg_stream>
    </mpt_stream>
  </legacy_stream>
  <legacy_stream name="stream2">
    <mpt_stream>
        <apg_stream>
          <fast_load_stream>
                <network_id>1</network_id>
                <objects>
                   <boot_event_object ref="BEO1"/>
                </objects>
          </fast_load_stream>
        </apg_stream>
    </mpt_stream>
  </legacy_stream>
  <legacy_stream name="stream3">
    <mpt_stream>
        <apg_stream>
          <fast_load_stream>
                <network_id>2</network_id>
                <objects>
                   <channel_object ref="CO3"/>
                   <channel_object ref="CO4"/>
                </objects>
          </fast_load_stream>
        </apg_stream>
    </mpt_stream>
  </legacy_stream>
</streams>


Another example is all channel_objects are in one network.
<streams>
  <legacy_stream name="stream1">
    <mpt_stream>
        <apg_stream>
          <fast_load_stream>
                <network_id>0</network_id>
                <objects>
                   <channel_object ref="CO1"/>
                   <channel_object ref="CO2"/>
                   <channel_object ref="CO3"/>
                   <channel_object ref="CO4"/>
                </objects>
          </fast_load_stream>
        </apg_stream>
    </mpt_stream>
  </legacy_stream>
  <legacy_stream name="stream2">
    <mpt_stream>
        <apg_stream>
          <fast_load_stream>
                <network_id>1</network_id>
                <objects>
                   <boot_event_object ref="BEO1"/>
                </objects>
          </fast_load_stream>
        </apg_stream>
    </mpt_stream>
  </legacy_stream>
  <legacy_stream name="stream3">
    <mpt_stream>
        <apg_stream>
          <fast_load_stream>
                <network_id>2</network_id>
                <objects>
                   <boot_event_object ref="BEO2"/>
                </objects>
          </fast_load_stream>
        </apg_stream>
    </mpt_stream>
  </legacy_stream>
</streams>


what output do you want from your posted input?
My output is also an xml file.  If all channel objects are in the same
network, I will store a true() boolean value in a global variable.
Otherwise I will store false(). This global variable I will use in other
part of my process. 


Here is the modify xslt file. It does find the right fast_load_stream.
Thanks David!  

<xsl:template match="/">
  <xsl:call-template name="isInSameNetwork"/>
</xsl:template>


<xsl:template name="isInSameNetwork">
  <xsl:param name="sumNetworks" select="0"/>
  <xsl:param name="nodes" select="//fast_load_stream"/>
  <xsl:if test="$nodes">                
    <xsl:choose>
      <xsl:when test="$nodes[1]/objects/channel_object" >
          <xsl:call-template name="isInSameNetwork">        
            <xsl:with-param name="sumNetworks" select="$sumNetworks + 1"
/>
            <xsl:with-param name="nodes"
select="$nodes[position()!=1]"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
          <xsl:call-template name="isInSameNetwork">
            <xsl:with-param name="sumNetworks" select="$sumNetworks" />
            <xsl:with-param name="nodes"
select="$nodes[position()!=1]"/>
          </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:if>

<xsl:if test="not($nodes)">
  <xsl:choose>
    <xsl:when test="$sumNetworks &gt; 1">
        <xsl:value-of select="false()"/>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="true()"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:if>       
</xsl:template>



David thanks again for your help. 

English is my second language. I spend a lot of time and effort to write
the email to post question in this mailing-list. I don't know that no
one understood my question cause no replies. I am sorry for that. I know
everyone is busy and time is valuable to everyone. It is possible to let
me know if you don't understand my question in a very short reply?  I
will try my best to illustrate that and clarify my question.


---- Jessica

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>