xsl-list
[Top] [All Lists]

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

2006-08-31 11:13:50
No one replays my question by now. I just send again to bring up your
attention. Thanks ahead.

-- Jessica

-----Original Message-----
From: Lin, Jessica [mailto:jlin(_at_)solekai(_dot_)com] 
Sent: Tuesday, August 29, 2006 4:44 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] failed to find the right child node

I am trying to find out whether all channel objects are in the same
networks. Each legacy_stream has a different network_id which indicates
different 
Networks. I plan to recursively check all fast_load stream, if it
contains channel object, I will increase sum of networks by 1. At the
end, I will check the sum of network, if it is larger than one, I will
assign a Boolean false value to indicate that all channels are in the
different network. Otherwise, I will assign a Boolean true value.
But, when I try to check each fast_load_stream by using  select
="//fast_load_stream[position()=$index]", it does not work. Could you
please help me to find out what's wrong in my code?


<?xml version="1.0" encoding="UTF-8"?>
<streams>
  <legacy_stream name="stream1">
    <mpt_stream>
        <apg_stream>
          <fast_load_stream>
                <network_id>0</network_id>
                <cycle_time_seconds>4</cycle_time_seconds>
                <objects>
                   <update_list_object ref="ULO1"/>
                   <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>
                <cycle_time_seconds>4</cycle_time_seconds>
                <objects>
                   <update_list_object ref="ULO2"/>
                   <channel_object ref="CO3"/>
                   <channel_object ref="CO4"/>
                </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>
                <cycle_time_seconds>4</cycle_time_seconds>
                <objects>
                   <update_list_object ref="ULO3"/>
                   <channel_object ref="CO5"/>
                   <channel_object ref="CO6"/>
                </objects>
          </fast_load_stream>
        </apg_stream>
    </mpt_stream>
  </legacy_stream>
</streams>


Here is my xslt file. I use some xsl:value-of to print out some outputs
for debug purpose. 


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="xml" encoding="UTF-8" indent="yes" />


<xsl:template match="/">
  <xsl:call-template name="isInSameNetwork">
    <xsl:with-param name="totalNetworks"
select="count(//fast_load_stream)"/>    
    </xsl:call-template>
</xsl:template>


<xsl:template name="isInSameNetwork">
  <xsl:param name="totalNetworks"/>
  <xsl:param name="index" select="1"/>
  <xsl:param name="sumNetworks" select="0"/>
  <xsl:value-of select="concat('#totalNetworks = ',
$totalNetworks, ', index = ', $index, ' sumNetworks = ',
$sumNetworks)"/>
  <xsl:variable name="fastloadStream"
select="//fast_load_stream[position()=$index]"/>
  <xsl:if test="$index &lt; $totalNetworks">            
    <xsl:choose>
        <xsl:when test="fastloadStream/objects/channel_object" >
           <xsl:text> $has COs </xsl:text>
           <xsl:call-template name="isInSameNetwork">
              <xsl:with-param name="totalNetworks"
select="$totalNetworks"/>
              <xsl:with-param name="index" select="$index + 1"/>
              <xsl:with-param name="sumNetworks" select="$sumNetworks +
1" />
           </xsl:call-template>
        </xsl:when>
     <xsl:otherwise>
          <xsl:text> $has no COs </xsl:text>
          <xsl:call-template name="isInSameNetwork">
             <xsl:with-param name="totalNetworks"
select="$totalNetworks"/>
             <xsl:with-param name="index" select="$index + 1"/>
             <xsl:with-param name="sumNetworks" select="$sumNetworks" />
          </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>
</xsl:if>

<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:template> 

</xsl:stylesheet>

--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>